Compare commits

..
18 Commits
Author SHA1 Message Date
Дмитрий 277ebba847 Restore the original realm before disposable SQUID recovery 2026-10-06 10:46:04 +05:00
Дмитрий 9a0b815937 Cover initial SQUID import and bot creation in startup budget 2026-10-06 10:42:08 +05:00
Дмитрий 78b84e11c2 Add disposable SQUID provisioning and repeated-start acceptance 2026-10-06 10:20:18 +05:00
Дмитрий 6aea9011f9 Allow first SQUID startup to complete large database imports 2026-10-06 10:12:13 +05:00
Дмитрий 171d9a2bf8 Add coordinated release packaging and disposable update acceptance 2026-10-06 10:08:54 +05:00
Дмитрий 0d6d8a0db8 Harden server update history, recovery guards and repeated checks 2026-10-06 07:01:13 +05:00
Дмитрий 3940506987 fix: update legacy Manager-patched realm launchers 2026-10-06 07:01:13 +05:00
Дмитрий 654b7cddd3 Keep SQUID settings usable with unknown metadata and preserve translations 2026-10-05 18:09:36 +05:00
Дмитрий f8301d7394 Read SQUID release settings and protect imported repack binaries 2026-10-05 16:56:46 +05:00
Corfirean cd3a963f70 Merge pull request #21 from Corfirean/codex/fix-update-startup
Release Manager 0.6.4: fix server startup and resume failed validation
2026-10-05 14:07:36 +05:00
Дмитрий 6c771fae20 feat: allow launching installed server and client without updates 2026-10-05 14:01:37 +05:00
Дмитрий cfe0889a4f Fix embedded launcher startup and retry applied updates safely 2026-10-05 13:53:32 +05:00
Corfirean 07ec22798f Merge pull request #19 from Corfirean/codex/release-all-pending
Release client-only connections and scaling controls in Manager 0.6.3
2026-10-05 03:26:16 +05:00
Дмитрий 5d865fcaea Prepare Manager 0.6.3 with remote clients and scaling settings 2026-10-05 03:15:05 +05:00
Дмитрий a67d51804b Expose partial LFG and open-world leech module settings 2026-10-05 03:09:02 +05:00
Дмитрий 7c096a4844 Merge remote-tracking branch 'origin/codex/client-only-mode' into codex/release-all-pending 2026-10-05 03:09:02 +05:00
Дмитрий f05f94ba01 Document standalone client connections 2026-10-05 01:24:01 +05:00
Дмитрий c39a7a0ac7 Let players download and update clients without a local server 2026-10-05 01:23:31 +05:00
79 changed files with 2454 additions and 210 deletions

No files matched your search

Generated
+3 -3
View File
@@ -491,7 +491,7 @@ dependencies = [
[[package]]
name = "coa-core"
version = "0.6.2"
version = "0.6.5"
dependencies = [
"base64 0.22.1",
"chrono",
@@ -519,7 +519,7 @@ dependencies = [
[[package]]
name = "coa-release"
version = "0.6.2"
version = "0.6.5"
dependencies = [
"chrono",
"coa-core",
@@ -528,7 +528,7 @@ dependencies = [
[[package]]
name = "coa-server-manager"
version = "0.6.2"
version = "0.6.5"
dependencies = [
"coa-core",
"serde",
+1 -1
View File
@@ -3,7 +3,7 @@ resolver = "2"
members = ["crates/coa-core", "crates/coa-release", "src-tauri"]
[workspace.package]
version = "0.6.2"
version = "0.6.5"
edition = "2021"
license = "AGPL-3.0-only"
+104
View File
@@ -0,0 +1,104 @@
# Urgent update hotfix
Deadline: 2026-10-06. This checkout starts at the exact v0.6.4 tag, commit
6c771fa, and excludes the ongoing isolated-trial/recovery redesign.
The client accepts checksum compatibility only from a verified signed manifest and only
for an Applied migration. It never updates the historical checksum, reruns historical
SQL, or excuses a Running/Failed ledger row. A server package must explicitly list the
verified published variants and append corrections under new migration IDs.
Current local evidence: the locked workspace tests passed, including 252 core tests
run serially. Six frontend logic tests and the frontend production build passed.
The hotfix runtime was tested against the exact signed candidate manifest on the marked
CoA/Wildcard fixture. Both published repair checksums were accepted independently in
both worlds, with zero migration executions, unchanged historical checksums, and unchanged
account, character and inventory counts. The original ledger rows were restored after
the test, and all fixture processes were stopped. A real Running or Failed repair row in
either world was rejected before staging or creating a transaction, with unchanged world
executable and installation metadata. Tests use independent hotfix metadata so experimental
transaction formats are not confused with the 0.6.4 upgrade path. Windows journal writes also use flushed
atomic replacement with long-path support. Changelog validation passed.
Additional guards implemented:
- Read migration history without creating its ledger before downloading or replacing files.
- Reject missing journals, invalid identities, paths, hashes and inconsistent operations.
Durable completed-cleanup markers distinguish interrupted pruning from a lost journal.
- Preserve all backups while an update is unfinished or its journal is damaged.
- Verify saved-file hashes and the complete database/configuration recovery point before
stopping services or changing files/databases. New snapshots include configuration hashes;
update journals bind their backup metadata to a hash.
- Surface state-reading errors in Settings and disable applying until the disk state is
successfully read. Checking again refreshes that state.
- Verify every extracted SQL artifact before taking the update snapshot or replacing
server files; missing files, invalid IDs, duplicate migrations and checksum disagreements
reject the update early. SQL application repeats the integrity check immediately before use.
- Count unapplied migrations in the active and secondary realms, counting shared auth once.
Matching versions and files do not hide remaining database work. Preview reads history
under the installation lock; a stopped database is temporarily started for inspection
and stopped again when no game services are running.
- Reread the disk state after every update/recovery attempt, including failed attempts and
background updates. Unfinished or unreadable state blocks another application in the UI.
- Acquire the installation lock before checking and deleting a backup.
Latest real-runtime test used the independently copied, doubly marked fixture
`C:\games\coa-schema-fixture-chaos-20261005-v1` and signed candidate `0.261005.24`, manifest SHA-256
`1284b1273815209c9621b6d173a2211bae316f33462ccbe8b578e53b8d26fb5b`.
All 1748 SQL artifacts passed verification after authenticated archive extraction.
Removing one repair record separately in CoA and Wildcard increased the pending count
by exactly one; restoring its original record restored the original count. No migrations
were executed, player counts were preserved and fixture services were stopped afterward.
The source checkout remains uncommitted; these results are not an installer acceptance report.
Additional acceptance on 2026-10-06: a new independent installation/database copy at
`C:\games\coa-schema-fixture-chaos-064-transition-20261006` received the authenticated
published `0.261005.22` program files, original CRLF repair checksum, and a deliberately
missing Wildcard table in both realms. The production hotfix update pipeline committed
signed candidate `0.261005.24`, repaired both realms, passed schema checks and actual
bundled-Python server startup, and preserved the selected account, character, item and
inventory fields byte-for-byte. The fixture was stopped afterward. The harness explicitly
instruments the launcher to prevent relay submissions and bind to localhost; this is not
proof of packaged UI behavior or operating-system network containment.
Local installer `C:\games\source\manager-065-local-installer-20261006\CoA Server Manager_0.6.5_x64-setup.exe`
has SHA-256 `520ee0391d923b92da0a20591e30006c048cdb60156275d7a829918bf1b77491`.
Its updater signature and the published 0.6.4 installer's signature passed independent
verification with the configured updater public key. Both executables extracted from
their exact NSIS packages started, created responsive windows, and were stopped using
an independent application/WebView profile. No installer was executed over a user's
installation, and no UI update operation was exercised.
Legacy limitation: old 0.6.4 transaction copies and configuration snapshots without recorded
hashes can be checked for presence and declared database hashes, but their original file
contents cannot be authenticated retroactively. Missing copies block restoration. This
hotfix does not claim that old unchecksummed copies received full integrity verification.
Remaining release requirements: reproduce the existing-user failures through the published
0.6.4 interface, verify legacy unfinished transaction handling on real-runtime fixtures,
and execute the exact installer over 0.6.4 in an isolated Windows environment with UI
state/settings/server-list verification. Windows native UI automation is unavailable in
this session. Packaged startup and signature checks do not satisfy that installer gate.
No public release has been made.
The user subsequently exercised the packaged UI: candidate 0.261005.24 committed and
both CoA and Wildcard were shown running. Repeat-check/restart acceptance is still pending.
The screenshots exposed an older published package being offered after the local candidate
was installed. Follow-up changes reject older packages before preview/database inspection
and application and clear a cached offer after a failed recheck. All 253 core tests and
seven frontend tests passed. The earlier installer hash above does not include this follow-up;
a separately recorded revision is required. Native UI control was subsequently initialized
through the deferred node_repl tool, then the user stopped automation with Escape and
performed the UI check manually.
Another user repeat-check exposed the already installed launcher being offered again.
The preview now verifies canonical launcher bytes against the current signed package,
caches those bytes by SHA-256, and compares only recognized Manager transformations.
The actual disposable fixture's repeat preview passed with all 104 files skipped and
zero pending SQL. User edits, recorded custom content, and a package with different
launcher bytes are not mistaken for that integration. All 254 core tests passed;
the strengthened regression test and seven frontend tests also passed. The first
preview of a managed launcher may download/extract its authenticated package to build
the optional canonical cache. Earlier installer revisions do not include this fix.
Do not recommend deleting an installation or replacing its player databases.
@@ -0,0 +1,7 @@
---
area: manager
type: added
audience: admins
title: Configure partial dungeon parties and open-world life steal in module settings
---
Choose whether Dungeon Finder enters with the current party and enable open-world life steal with a healing percentage from 0 to 100. Available on server builds that support these options.
@@ -0,0 +1,7 @@
---
area: manager
type: added
audience: players
title: Download and update the game client without installing a server
---
Choose to host a server or connect to someone else's. Players joining a friend can download, update and launch the client, save the host's address and use the Manager without installing a local server.
@@ -0,0 +1,7 @@
---
area: manager
type: added
audience: admins
title: Imported SquidBots servers warn before replacing their original binary
---
Imports explain that the original launcher and updater check the server binary hash. Updating that binary requires an explicit choice to keep or replace it.
@@ -0,0 +1,7 @@
---
area: manager
type: added
audience: players
title: Start your installed server or client without downloading an available update
---
Choose to update later and keep playing with your installed version. Interrupted server updates still require recovery before startup.
@@ -0,0 +1,7 @@
---
area: manager
type: fixed
audience: admins
title: Finish a server update that was blocked by a startup failure
---
The Manager repairs the launcher import path and lets you retry startup for an already applied update. Successful validation finishes the update without replaying SQL or restoring old databases. Failure details are preserved and rollback remains available.
@@ -0,0 +1,7 @@
---
area: manager
type: added
audience: admins
title: SquidBots settings follow the options shipped by the module
---
New settings use the module's descriptions, groups, defaults and value limits while retaining existing translations. Unknown formats or invalid fields use built-in controls so the settings page remains available.
@@ -0,0 +1,7 @@
---
area: manager
type: added
audience: admins
title: SquidBots shows its bundled release and includes it in problem reports
---
The Bots and Modules pages and problem reports include the release identifiers. Imported repacks use their recorded bot revision; empty tags are hidden. The settings file's source commit is not presented as the build revision.
@@ -0,0 +1,7 @@
---
area: manager
type: fixed
audience: admins
title: Server updates accept verified published migration variants without rerunning them
---
Signed updates can recognise known published checksums without changing your migration history. Interrupted or failed SQL still requires recovery before retrying.
@@ -0,0 +1,7 @@
---
area: manager
type: fixed
audience: admins
title: Server updates replace older launchers adapted by the Manager for Wildcard
---
Updates recognize the Manager’s own realm and import adjustments even when older metadata still records the original launcher. New server binaries receive their matching launcher; genuine custom edits still require your decision.
@@ -0,0 +1,7 @@
---
area: manager
type: fixed
audience: admins
title: Older server packages cannot replace a newer installation
---
Update checks stop offering stale packages after an update. To undo an update, use its recovery point instead of applying an older server package.
@@ -0,0 +1,7 @@
---
area: manager
type: fixed
audience: admins
title: Checking again no longer offers an already installed launcher update
---
The Manager recognizes its own launcher integration while still detecting user edits and changes in newer signed packages.
@@ -0,0 +1,7 @@
---
area: manager
type: fixed
audience: admins
title: Large SQUID database imports have more time to finish on first startup
---
The Manager allows up to 45 minutes when SQUID Playerbots is enabled, covering its initial database import and bot creation. Ordinary server startup and shutdown keep their existing deadlines.
@@ -0,0 +1,7 @@
---
area: manager
type: fixed
audience: admins
title: Update history conflicts are detected before server files change
---
Damaged update records block changes and remain visible. Recovery checks saved copies before restoring, and unfinished updates protect backups from deletion and cleanup.
@@ -0,0 +1,7 @@
---
area: manager
type: fixed
audience: admins
title: Pending database updates remain visible when the server version matches
---
SQL files are checked before replacing server files. Update and recovery attempts refresh their saved status, including errors. Backup deletion cannot race with an update.
+1 -1
View File
@@ -31,7 +31,7 @@ rand_core = { version = "0.6", features = ["getrandom"] }
ed25519-dalek = { version = "2", features = ["rand_core"] }
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.60", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_System_SystemInformation", "Win32_System_Diagnostics_ToolHelp", "Win32_NetworkManagement_IpHelper", "Win32_Networking_WinSock"] }
windows-sys = { version = "0.60", features = ["Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_Threading", "Win32_System_SystemInformation", "Win32_System_Diagnostics_ToolHelp", "Win32_NetworkManagement_IpHelper", "Win32_Networking_WinSock"] }
[features]
testkit = []
@@ -0,0 +1,38 @@
use std::{fs, path::PathBuf};
use coa_core::{manifest::{Kind, Manifest}, package::{self, BuildOptions}, pkgsource::{self, Source}, release, signing, Result};
fn main() -> Result<()> {
let args: Vec<String> = std::env::args().skip(1).collect();
let source = Source::Dir(args[1].clone().into());
let (previous, _) = pkgsource::fetch_manifest(&source, signing::EMBEDDED_PUBLIC_KEY)?;
let tree = PathBuf::from(&args[2]);
if args[0] == "extract" {
assert!(!tree.exists(), "Use a new release tree");
package::extract(&PathBuf::from(&args[1]), &previous, &tree, &|_, _| {})?;
println!("Verified and extracted {}: {} historical migrations", previous.version, previous.migrations.len());
return Ok(());
}
assert_eq!(args[0], "pack");
let out = PathBuf::from(&args[3]);
assert!(!out.exists(), "Release addresses must be immutable");
for migration in &previous.migrations {
let entry = previous.files.iter().find(|file| file.path.starts_with("_migrations/") && file.sha256 == migration.sha256).expect("Historical SQL entry");
assert_eq!(coa_core::fsx::sha256_file(&tree.join(&entry.path))?, entry.sha256, "Historical SQL changed: {}", migration.id);
}
let mut manifest = package::build(&tree, &out, &BuildOptions {
kind: Kind::Update, version: args[4].clone(), core_commit: Some(args[5].clone()),
bots_commit: previous.bots.and_then(|revision| revision.commit),
built_at: chrono::Utc::now().to_rfc3339(), part_size: package::DEFAULT_PART_SIZE,
migrations: previous.migrations.clone(),
}, &|line| println!("{line}"))?;
manifest.min_manager_version = "0.6.5".into();
manifest.validate()?;
coa_core::fsx::atomic_write(&out.join("manifest.json"), &serde_json::to_vec_pretty(&manifest)?)?;
let key_path = PathBuf::from(std::env::var("USERPROFILE").unwrap()).join(".coa-manager/signing/manifest-signing.key");
release::sign_manifest(&out, &fs::read_to_string(key_path)?)?;
coa_core::release_schema::verify_package(&out, signing::EMBEDDED_PUBLIC_KEY)?;
let reread: Manifest = serde_json::from_slice(&fs::read(out.join("manifest.json"))?)?;
assert_eq!(serde_json::to_value(reread.migrations)?, serde_json::to_value(previous.migrations)?);
println!("PASS: signed {}; all historical migration bytes, checksums, aliases and order preserved", manifest.version);
Ok(())
}
@@ -0,0 +1,70 @@
use std::path::{Path, PathBuf};
use coa_core::{backup, driver, fsx, Result};
fn set(root: &Path, filename: &str, values: &[(&str, &str)]) -> Result<()> {
let path = root.join("Core/configs/modules").join(filename);
let mut config = coa_core::config::parser::ConfFile::parse_bytes(&std::fs::read(&path)?)?;
for (key, value) in values { config.set(key, value, &[]); }
fsx::atomic_write(&path, config.to_text().as_bytes())
}
fn ledgers(root: &Path) -> Result<Vec<String>> {
backup::with_database(root, |db| ["acore_playerbots", "acore_world", "acore_characters"].into_iter()
.map(|schema| db.query(&format!("SELECT path,sha256 FROM `{schema}`.coa_squid_migrations ORDER BY path;"))).collect())
}
fn exercise(root: &Path) -> Result<()> {
let meta = coa_core::registry::metadata_dir_for(root)?;
let point = backup::create(root, &meta, backup::Kind::Full, backup::Trigger::Manual, Some("Disposable SQUID acceptance".into()), &|stage| println!("{stage}"))?;
assert!(backup::verify(&meta, &point.id)?.ok);
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| -> Result<()> {
backup::with_database(root, |db| db.query("DROP DATABASE IF EXISTS acore_playerbots;").map(|_| ()))?;
assert!(driver::run(root, driver::Verb::StartAll)?.ok, "Disabled SQUID must start without its database");
assert!(driver::run(root, driver::Verb::StopAll)?.ok);
coa_core::multiworld::set_enabled(root, false)?;
coa_core::realms::select(root, coa_core::realms::Mode::Coa)?;
set(root, "mod_coa_playerbots.conf", &[("CoaBots.Enable", "0")])?;
set(root, "playerbots.conf", &[("AiPlayerbot.Enabled", "1"), ("AiPlayerbot.RandomBotAutologin", "0"), ("AiPlayerbot.MinRandomBots", "0"), ("AiPlayerbot.MaxRandomBots", "0"), ("AiPlayerbot.RandomBotGuildCount", "0"), ("AiPlayerbot.RandomBotAccountCount", "0")])?;
let started = driver::run(root, driver::Verb::StartAll)?;
assert!(started.ok, "Fresh SQUID startup: {}", coa_core::diag::redact(&started.output));
let before = ledgers(root)?;
assert!(!before[0].is_empty(), "Fresh SQUID history missing");
assert!(driver::run(root, driver::Verb::StopAll)?.ok);
let started = driver::run(root, driver::Verb::StartAll)?;
assert!(started.ok, "Repeated SQUID startup: {}", coa_core::diag::redact(&started.output));
assert_eq!(ledgers(root)?, before, "SQUID replay changed its migration history");
println!("PASS: SQUID-disabled dual startup without its database; fresh enabled SQUID import and startup; repeated startup preserves all three histories");
Ok(())
}));
assert!(driver::run(root, driver::Verb::StopAll)?.ok);
restore(root, &meta, &point)?;
result.map_err(|_| coa_core::Error::Invalid("SQUID acceptance failed; disposable databases and configurations restored".into()))?
}
fn restore(root: &Path, meta: &Path, point: &backup::RecoveryPoint) -> Result<()> {
assert!(backup::verify(meta, &point.id)?.ok);
assert!(driver::run(root, driver::Verb::StopAll)?.ok);
coa_core::realms::select(root, point.realm)?;
for component in point.components.iter().filter(|component| component.name != "configs") {
backup::restore_database(root, meta, &point.id, &component.name)?;
}
backup::restore_configs(root, meta, &point.id)?;
assert!(driver::run(root, driver::Verb::StopAll)?.ok);
println!("PASS: disposable SQUID acceptance databases and original realm configurations restored");
Ok(())
}
fn main() -> Result<()> {
let root = PathBuf::from(std::env::args().nth(1).unwrap());
assert!(root.file_name().unwrap().to_string_lossy().starts_with("coa-schema-fixture-chaos-064-transition-"));
assert_eq!(std::fs::read(root.join(".transition-fixture"))?, b"disposable published-064 transition fixture");
assert!(!root.join("Data").symlink_metadata()?.file_type().is_symlink());
assert!(driver::run(&root, driver::Verb::StopAll)?.ok);
if let Some(id) = std::env::args().nth(2) {
let meta = coa_core::registry::metadata_dir_for(&root)?;
return restore(&root, &meta, &backup::get(&meta, &id)?);
}
let result = exercise(&root);
assert!(driver::run(&root, driver::Verb::StopAll)?.ok);
result
}
@@ -0,0 +1,54 @@
use std::{collections::BTreeMap, path::PathBuf};
use coa_core::{backup, driver, registry::MetaDir, update::{self, RepackEnv}, Result};
fn players(db: &coa_core::db::Db) -> Result<String> {
db.query("SELECT CONCAT(id,':',username,':',HEX(salt),':',HEX(verifier)) FROM acore_auth.account WHERE id=900001; SELECT CONCAT(guid,':',account,':',name,':',level,':',money) FROM acore_characters.characters WHERE guid=900001; SELECT CONCAT(guid,':',itemEntry,':',owner_guid,':',enchantments) FROM acore_characters.item_instance WHERE guid=900001; SELECT CONCAT(guid,':',bag,':',slot,':',item) FROM acore_characters.character_inventory WHERE guid=900001;")
}
fn exercise(root: &std::path::Path, package: &str) -> Result<()> {
let meta_dir = coa_core::registry::metadata_dir_for(root)?;
let (_, meta) = MetaDir::open(&meta_dir)?;
let expected = backup::with_database(root, |db| [coa_core::realms::Mode::Coa, coa_core::realms::Mode::Wildcard].into_iter().map(|mode| players(&db.clone().for_realm(mode))).collect::<Result<Vec<_>>>())?;
assert!(driver::run(root, driver::Verb::StopAll)?.ok);
let source = coa_core::pkgsource::Source::Dir(package.into());
let preview = update::preview(root, &meta, &source, coa_core::signing::EMBEDDED_PUBLIC_KEY, &BTreeMap::new())?;
assert_eq!(preview.pending_migrations, 0, "Historical SQL must not replay");
assert!(!preview.items.iter().any(|item| item.action == update::Action::Conflict), "Unresolved candidate files: {:?}", preview.items);
let environment = RepackEnv { root, meta_dir: &meta_dir };
let outcome = update::apply(&update::Params {
root, meta_dir: &meta_dir, source, trusted_key: coa_core::signing::EMBEDDED_PUBLIC_KEY,
resolutions: BTreeMap::new(), cancel: Default::default(), env: &environment, fail_after_ops: None,
}, &|stage, progress| println!("{progress}% {stage}"))?;
assert_eq!(outcome.txn.state, update::State::Committed, "{:?}", outcome.txn);
backup::with_database(root, |db| {
for (index, mode) in [coa_core::realms::Mode::Coa, coa_core::realms::Mode::Wildcard].into_iter().enumerate() {
let realm = db.clone().for_realm(mode);
assert_eq!(players(&realm)?, expected[index], "Player data changed in {mode:?}");
let problems = coa_core::schema_check::check(&realm, root)?;
assert!(problems.is_empty(), "{problems:?}");
}
Ok(())
})?;
let release = coa_core::squid::release(root).expect("SQUID release metadata");
println!("SQUID metadata: {release:?}");
assert_eq!(coa_core::squid::fields(root)?.len(), 40);
let (_, installed) = MetaDir::open(&meta_dir)?;
let repeated = update::preview(root, &installed, &coa_core::pkgsource::Source::Dir(package.into()), coa_core::signing::EMBEDDED_PUBLIC_KEY, &BTreeMap::new())?;
assert_eq!(repeated.pending_migrations, 0);
assert!(repeated.items.iter().all(|item| item.action == update::Action::Skip), "{:?}", repeated.items);
println!("PASS: coordinated update committed, both realms started, player fields preserved, historical SQL skipped, repeated preview clean");
Ok(())
}
fn main() -> Result<()> {
let args: Vec<String> = std::env::args().skip(1).collect();
let root = PathBuf::from(&args[0]);
assert!(root.file_name().unwrap().to_string_lossy().starts_with("coa-schema-fixture-chaos-064-transition-"));
assert_eq!(std::fs::read(root.join(".transition-fixture"))?, b"disposable published-064 transition fixture");
assert_eq!(std::fs::read(root.join(".release-schema-fixture"))?, b"disposable release-schema fixture");
assert!(!root.join("Data").symlink_metadata()?.file_type().is_symlink());
assert!(driver::run(&root, driver::Verb::StopAll)?.ok);
let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| exercise(&root, &args[1])));
assert!(driver::run(&root, driver::Verb::StopAll)?.ok, "Fixture shutdown failed");
outcome.map_err(|_| coa_core::Error::Invalid("Disposable coordinated acceptance failed; stopped services and retained recovery copies".into()))?
}
@@ -0,0 +1,93 @@
//! Verify published checksum compatibility on a disposable real database, without running SQL migrations.
use std::{path::{Path, PathBuf}, sync::atomic::{AtomicUsize, Ordering}};
use coa_core::{backup, db::Db, migrations::{self, LedgerRow, Status, Store}, pkgsource::{self, Source}, Result};
struct Observed<'a> { db: &'a Db, executions: AtomicUsize }
impl Store for Observed<'_> {
fn load(&self) -> Result<Vec<LedgerRow>> { self.db.load() }
fn put(&self, row: &LedgerRow) -> Result<()> { self.db.put(row) }
fn run_file(&self, _: &str, _: &Path) -> Result<()> {
self.executions.fetch_add(1, Ordering::SeqCst);
panic!("Historical SQL must never be replayed");
}
}
fn main() -> Result<()> {
let args: Vec<_> = std::env::args().skip(1).collect();
let root = PathBuf::from(&args[0]);
assert!(root.file_name().unwrap().to_string_lossy().starts_with("coa-schema-fixture-chaos-"));
assert_eq!(std::fs::read(root.join(".coa-chaos-fixture"))?, b"disposable update chaos fixture");
assert_eq!(std::fs::read(root.join(".release-schema-fixture"))?, b"disposable release-schema fixture");
let source = Source::Dir(PathBuf::from(&args[1]));
let package = pkgsource::fetch_manifest(&source, coa_core::signing::EMBEDDED_PUBLIC_KEY)?.0;
let staging = tempfile::tempdir()?;
let parts = pkgsource::fetch_parts(&source, &package, &staging.path().join("download"), &Default::default(), &|_, _| {})?;
coa_core::package::extract(&parts, &package, &staging.path().join("tree"), &|_, _| {})?;
migrations::verify_files(&package.migrations, &staging.path().join("tree/_migrations"))?;
println!("PASS: all {} signed-package SQL artifacts verified before any database mutation", package.migrations.len());
let migration = package.migrations.iter().find(|m| m.id == "manager_repair__20261005_missing_wildcard_tables").unwrap();
let hashes = ["c1d8dbf2271234283a48a39e4b4aea1106b83b70581f1e3c4aa9fff438e8e4d2", "9e4a36245c3f83255415c122c01f08ceb3e3b83898d3d427ac4e2fbcf61e9638"];
for hash in hashes { assert!(migration.sha256 == hash || migration.compatible_sha256.iter().any(|h| h == hash)); }
let fixture_meta = coa_core::registry::metadata_dir_for(&root)?;
let test_meta = tempfile::tempdir()?;
coa_core::fsx::atomic_write(&test_meta.path().join("install.json"), &std::fs::read(fixture_meta.join("install.json"))?)?;
coa_core::registry::MetaDir::open(test_meta.path())?;
std::fs::create_dir_all(test_meta.path().join("updates"))?;
let result = backup::with_database(&root, |db| {
let mut modes = vec![coa_core::realms::Mode::Coa];
if coa_core::realms::state(&root)?.wildcard_created { modes.push(coa_core::realms::Mode::Wildcard); }
for mode in modes {
let db = db.clone().for_realm(mode);
let saved = db.load()?.into_iter().find(|row| row.id == migration.id && row.db == migration.db).expect("Published repair must already be applied");
assert_eq!(saved.status, Status::Applied);
let counts = db.query("SELECT CONCAT((SELECT COUNT(*) FROM acore_characters.characters),':',(SELECT COUNT(*) FROM acore_characters.item_instance),':',(SELECT COUNT(*) FROM acore_auth.account));")?;
let check = || -> Result<()> {
for hash in hashes {
db.put(&LedgerRow { sha256: hash.into(), ..saved.clone() })?;
let observed = Observed { db: &db, executions: AtomicUsize::new(0) };
migrations::preflight(&db, std::slice::from_ref(migration))?;
let report = migrations::apply_pending(&observed, std::slice::from_ref(migration), &root.join(".unused-hotfix-sql"), &|| panic!("Already applied SQL needs no snapshot"))?;
assert!(report.applied.is_empty());
assert_eq!(observed.executions.load(Ordering::SeqCst), 0);
assert_eq!(db.load()?.into_iter().find(|r| r.id == migration.id && r.db == migration.db).unwrap().sha256, hash);
}
let meta = test_meta.path();
let file_hash = coa_core::fsx::sha256_file(&root.join("Core/worldserver.exe"))?;
let install_hash = coa_core::fsx::sha256_file(&meta.join("install.json"))?;
let transaction_count = std::fs::read_dir(meta.join("updates"))?.count();
for status in [Status::Running, Status::Failed] {
db.put(&LedgerRow { status, ..saved.clone() })?;
let env = coa_core::update::RepackEnv { root: &root, meta_dir: meta };
let rejected = coa_core::update::apply(&coa_core::update::Params {
root: &root, meta_dir: meta, source: Source::Dir(PathBuf::from(&args[1])),
trusted_key: coa_core::signing::EMBEDDED_PUBLIC_KEY, cancel: Default::default(),
resolutions: Default::default(), env: &env, fail_after_ops: None,
}, &|_, _| {});
let message = rejected.unwrap_err().to_string();
assert!(message.contains("partially applied"), "Unexpected rejection: {message}");
assert_eq!(std::fs::read_dir(meta.join("updates"))?.count(), transaction_count);
assert_eq!(coa_core::fsx::sha256_file(&root.join("Core/worldserver.exe"))?, file_hash);
assert_eq!(coa_core::fsx::sha256_file(&meta.join("install.json"))?, install_hash);
}
db.put(&saved)?;
let env = coa_core::update::RepackEnv { root: &root, meta_dir: meta };
let pending_before = env.pending_migrations(&package)?;
db.query("DELETE FROM acore_world.coa_manager_migrations WHERE db='characters' AND id='manager_repair__20261005_missing_wildcard_tables';")?;
assert_eq!(env.pending_migrations(&package)?, pending_before + 1,
"Missing history in either realm must remain visible even with identical server files");
db.put(&saved)?;
assert_eq!(env.pending_migrations(&package)?, pending_before);
Ok(())
};
let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(check));
db.put(&saved)?;
result.map_err(|_| coa_core::Error::Invalid("History regression assertion failed; the injected ledger row was restored.".into()))??;
assert_eq!(db.query("SELECT CONCAT((SELECT COUNT(*) FROM acore_characters.characters),':',(SELECT COUNT(*) FROM acore_characters.item_instance),':',(SELECT COUNT(*) FROM acore_auth.account));")?, counts);
println!("PASS: {} published checksums; Running/Failed rejected before staging; missing migration counted; zero SQL replays; history and player counts preserved", mode.name());
}
Ok(())
});
assert!(coa_core::driver::run(&root, coa_core::driver::Verb::StopAll)?.ok);
result?;
Ok(())
}
@@ -0,0 +1,16 @@
//! Read-only update preview against the marked disposable acceptance fixture.
use std::{collections::BTreeMap,path::PathBuf};
fn main()->coa_core::Result<()> {
let args:Vec<_>=std::env::args().skip(1).collect();
let root=PathBuf::from(&args[0]);
assert!(root.file_name().unwrap().to_string_lossy().starts_with("coa-schema-fixture-chaos-064-transition-"));
assert_eq!(std::fs::read(root.join(".transition-fixture"))?,b"disposable published-064 transition fixture");
let meta_dir=coa_core::registry::metadata_dir_for(&root)?;
let (_,meta)=coa_core::registry::MetaDir::open(&meta_dir)?;
let preview=coa_core::update::preview(&root,&meta,&coa_core::pkgsource::Source::Dir(args[1].clone().into()),coa_core::signing::EMBEDDED_PUBLIC_KEY,&BTreeMap::new())?;
assert_eq!(preview.from_version.as_deref(),Some(preview.to_version.as_str()));
assert_eq!(preview.pending_migrations,0);
assert!(preview.items.iter().all(|item|item.action==coa_core::update::Action::Skip),"{:?}",preview.items.iter().filter(|item|item.action!=coa_core::update::Action::Skip).collect::<Vec<_>>());
println!("PASS: real fixture repeated preview: {} files unchanged, zero pending SQL, no update offered",preview.items.len());
Ok(())
}
@@ -0,0 +1,165 @@
//! Real signed-package transition on an independent, explicitly marked disposable copy.
//! The Env wrapper instruments only launcher isolation; migration/backup/update code is production code.
use std::{collections::BTreeMap, path::{Path, PathBuf}};
use coa_core::{backup, driver, fsx, migrations, pkgsource::{self, Source}, registry::{InstallMeta, MetaDir}, update::{self, Env, RepackEnv}, Result};
struct Offline<'a>(RepackEnv<'a>);
impl Env for Offline<'_> {
fn ensure_stopped(&self) -> Result<()> { self.0.ensure_stopped() }
fn preflight(&self, m: &coa_core::manifest::Manifest) -> Result<()> { self.0.preflight(m) }
fn verify_snapshot(&self, id: &str) -> Result<()> { self.0.verify_snapshot(id) }
fn snapshot(&self) -> Result<String> { self.0.snapshot() }
fn restore_snapshot(&self, id: &str) -> Result<()> { self.0.restore_snapshot(id) }
fn migrate(&self, m: &coa_core::manifest::Manifest, p: &Path) -> Result<migrations::ApplyReport> { self.0.migrate(m,p) }
fn validate(&self) -> Result<()> {
let path=self.0.root.join("Scripts/manage.py");
let source=std::fs::read_to_string(&path)?.replace("\r\n", "\n");
// Explicit test instrumentation prevents relay transmissions and binds services locally.
let guarded=source.replace("def spawn(name, command, cwd, log):\n", "def spawn(name, command, cwd, log):\n for filename in ('worldserver.conf', 'authserver.conf'):\n path = ROOT / 'Core/configs' / filename\n if path.exists():\n text = path.read_text(encoding='utf-8-sig')\n for key, value in (('BindIP', '\"127.0.0.1\"'), ('Ra.IP', '\"127.0.0.1\"'), ('SOAP.Enabled', '0')):\n text = re.sub(r'(?m)^\\s*' + re.escape(key) + r'\\s*=.*$', '', text)\n text += '\\n' + key + ' = ' + value + '\\n'\n path.write_text(text, encoding='utf-8')\n").replace("def relay_worker():\n", "def relay_worker():\n save_process('relay-ready', os.getpid())\n while not (STATE / 'stop-relay').exists():\n time.sleep(0.5)\n return\n");
assert_ne!(source,guarded,"Fixture launcher isolation failed");
fsx::atomic_write(&path,guarded.as_bytes())?;
self.0.validate()
}
}
fn players(db: &coa_core::db::Db) -> Result<String> {
db.query("SELECT CONCAT(id,':',username,':',HEX(salt),':',HEX(verifier)) FROM acore_auth.account WHERE id=900001; SELECT CONCAT(guid,':',account,':',name,':',level,':',money) FROM acore_characters.characters WHERE guid=900001; SELECT CONCAT(guid,':',itemEntry,':',owner_guid,':',enchantments) FROM acore_characters.item_instance WHERE guid=900001; SELECT CONCAT(guid,':',bag,':',slot,':',item) FROM acore_characters.character_inventory WHERE guid=900001;")
}
fn main() -> Result<()> {
let args:Vec<_>=std::env::args().skip(1).collect();
let root=PathBuf::from(&args[0]);
assert!(root.file_name().unwrap().to_string_lossy().starts_with("coa-schema-fixture-chaos-064-transition-"));
assert_eq!(std::fs::read(root.join(".transition-fixture"))?,b"disposable published-064 transition fixture");
if args.get(3).is_some_and(|mode| mode=="legacy-recovery") {
return run_fixture(&root,||legacy_recovery(&root));
}
assert!(!root.join(".transition-started").exists(),"Use a new independent fixture");
fsx::atomic_write(&root.join(".transition-started"),b"started")?;
let meta=coa_core::registry::metadata_dir_for(&root)?;
assert!(!meta.exists(),"Do not reuse experimental or user metadata");
run_fixture(&root,||exercise(&root,&meta,&args[1],&args[2]))
}
fn run_fixture(root:&Path,operation:impl FnOnce()->Result<()>)->Result<()> {
let result=std::panic::catch_unwind(std::panic::AssertUnwindSafe(operation));
assert!(driver::run(root,driver::Verb::StopAll)?.ok,"Fixture shutdown failed");
result.map_err(|_|coa_core::Error::Invalid("Disposable acceptance assertion failed; services were stopped and recovery copies retained.".into()))?
}
fn legacy_recovery(root:&Path)->Result<()> {
let meta=coa_core::registry::metadata_dir_for(root)?;
assert!(driver::run(root,driver::Verb::StopAll)?.ok);
let expected=backup::with_database(root,|db| [coa_core::realms::Mode::Coa,coa_core::realms::Mode::Wildcard].into_iter().map(|mode|players(&db.clone().for_realm(mode))).collect::<Result<Vec<_>>>())?;
assert!(driver::run(root,driver::Verb::StopAll)?.ok);
let dirs=std::fs::read_dir(meta.join("updates"))?.collect::<std::io::Result<Vec<_>>>()?;
assert_eq!(dirs.len(),1,"Requires exactly the preceding successful disposable transition");
let txn_dir=dirs[0].path();
let journal=txn_dir.join("txn.json");
let mut legacy:serde_json::Value=fsx::read_json(&journal)?;
assert_eq!(legacy["state"],"committed");
let point=legacy["recovery_point"].as_str().unwrap().to_string();
let point_path=meta.join("backups").join(&point).join("backup.json");
let mut point_json:serde_json::Value=fsx::read_json(&point_path)?;
point_json["manager_version"]="0.6.4".into();
for component in point_json["components"].as_array_mut().unwrap() { component.as_object_mut().unwrap().remove("file_sha256"); }
fsx::atomic_write_json(&point_path,&point_json)?;
legacy.as_object_mut().unwrap().remove("recovery_hashes");
legacy.as_object_mut().unwrap().remove("databases_started");
legacy["state"]="applied".into();
fsx::atomic_write_json(&journal,&legacy)?;
assert!(update::ensure_recovered(&meta).is_err(),"Legacy unfinished update must block startup");
let id=legacy["id"].as_str().unwrap();
let env=RepackEnv {root,meta_dir:&meta};
println!("Recovering legacy-format transaction and recovery point on disposable installation");
assert_eq!(update::rollback(root,&meta,id,&env)?.state,update::State::RolledBack);
for op in legacy["ops"].as_array().unwrap() {
let relative=op["path"].as_str().unwrap();
if op["had_previous"]==true {
assert_eq!(fsx::sha256_file(&fsx::safe_join(root,relative)?)?,fsx::sha256_file(&fsx::safe_join(&txn_dir.join("before"),relative)?)?,"Legacy file restoration mismatch: {relative}");
} else { assert!(!fsx::safe_join(root,relative)?.exists()); }
}
assert_eq!(std::fs::read(meta.join("install.json"))?,std::fs::read(txn_dir.join("before/manager-install.json"))?);
backup::with_database(root,|db| {
for (index,mode) in [coa_core::realms::Mode::Coa,coa_core::realms::Mode::Wildcard].into_iter().enumerate() {
let db=db.clone().for_realm(mode);
assert_eq!(players(&db)?,expected[index]);
assert_eq!(db.query("SELECT COUNT(*) FROM acore_world.coa_manager_migrations WHERE id IN ('manager_repair__20261005_reconcile_wildcard_tables','manager_repair__20261005_reconcile_missing_class_starts');")?,"0");
assert_eq!(db.query("SELECT sha256 FROM acore_world.coa_manager_migrations WHERE id='manager_repair__20261005_missing_wildcard_tables';")?,"9e4a36245c3f83255415c122c01f08ceb3e3b83898d3d427ac4e2fbcf61e9638");
}
Ok(())
})?;
assert!(driver::run(root,driver::Verb::StopAll)?.ok);
assert!(update::pending_checked(&meta)?.is_none());
assert!(update::rollback(root,&meta,id,&env).is_err(),"Completed recovery must not run again");
println!("PASS: legacy journal blocked startup; old files, metadata, migration histories and player fields restored; completed recovery rejects replay. Original baseline had a missing table, so healthy startup is not claimed after rollback.");
Ok(())
}
fn exercise(root:&Path,meta:&Path,baseline:&str,candidate:&str)->Result<()> {
let mut install:InstallMeta=fsx::read_json(&PathBuf::from("C:/games/coa-schema-fixture-chaos-20261005-v1.manager/install.json"))?;
install.server_path=root.to_string_lossy().into_owned();
install.id=uuid::Uuid::new_v4().to_string();
install.manager_version="0.6.4".into();
MetaDir::create(root,&install)?;
// Private ports, and no inherited PID records or paths to the source database.
let mut cfg:serde_json::Value=fsx::read_json(&root.join("Settings/repack.json"))?;
let mut listeners=Vec::new();
for key in ["mysqlPort","authPort","worldPort","raPort"] {
let listener=std::net::TcpListener::bind("127.0.0.1:0")?;
cfg[key]=listener.local_addr()?.port().into(); listeners.push(listener);
}
fsx::atomic_write_json(&root.join("Settings/repack.json"),&cfg)?;
let mut profile:serde_json::Value=fsx::read_json(&root.join("Settings/realm-profile.json"))?;
for key in ["secondary_world_port","secondary_ra_port"] {
let listener=std::net::TcpListener::bind("127.0.0.1:0")?;
profile[key]=listener.local_addr()?.port().into(); listeners.push(listener);
}
fsx::atomic_write_json(&root.join("Settings/realm-profile.json"),&profile)?;
drop(listeners);
let state=root.join(".state");
if state.exists() { std::fs::remove_dir_all(&state)?; }
let secondary_state=root.join(".realms/secondary/.state");
if secondary_state.exists() { std::fs::remove_dir_all(&secondary_state)?; }
let source=Source::Dir(baseline.into());
let (manifest,_)=pkgsource::fetch_manifest(&source,coa_core::signing::EMBEDDED_PUBLIC_KEY)?;
let temp=tempfile::tempdir()?;
let parts=pkgsource::fetch_parts(&source,&manifest,&temp.path().join("download"),&Default::default(),&|_,_|{})?;
let tree=temp.path().join("tree");
coa_core::package::extract(&parts,&manifest,&tree,&|_,_|{})?;
for file in &manifest.files {
if file.path.starts_with("_migrations/") {continue;}
fsx::atomic_write(&fsx::safe_join(root,&file.path)?,&std::fs::read(fsx::safe_join(&tree,&file.path)?)?)?;
install.original_hashes.insert(file.path.clone(),file.sha256.clone());
}
install.core.version=Some(manifest.version);
fsx::atomic_write_json(&meta.join("install.json"),&install)?;
// Both worlds must remain local, including generated secondary configuration.
for relative in ["Settings/worldserver.conf.template","Settings/authserver.conf.template"] {
let p=root.join(relative);
let mut conf=coa_core::config::parser::ConfFile::parse_bytes(&std::fs::read(&p)?)?;
conf.set("BindIP","\"127.0.0.1\"",&[]); conf.set("Ra.IP","\"127.0.0.1\"",&[]); conf.set("SOAP.Enabled","0",&[]);
fsx::atomic_write(&p,conf.to_text().as_bytes())?;
}
let expected=backup::with_database(root,|db| {
let mut saved=Vec::new();
for mode in [coa_core::realms::Mode::Coa,coa_core::realms::Mode::Wildcard] {
let db=db.clone().for_realm(mode);
saved.push(players(&db)?);
db.query("DROP TABLE IF EXISTS acore_characters.coa_wildcard_skill_card; DELETE FROM acore_world.coa_manager_migrations WHERE id IN ('manager_repair__20261005_reconcile_wildcard_tables','manager_repair__20261005_reconcile_missing_class_starts'); UPDATE acore_world.coa_manager_migrations SET sha256='9e4a36245c3f83255415c122c01f08ceb3e3b83898d3d427ac4e2fbcf61e9638' WHERE id='manager_repair__20261005_missing_wildcard_tables' AND status='applied';")?;
}
Ok(saved)
})?;
let source=Source::Dir(candidate.into());
let candidate_manifest=pkgsource::fetch_manifest(&source,coa_core::signing::EMBEDDED_PUBLIC_KEY)?.0;
let choices:BTreeMap<_,_>=update::plan(root,&install,&candidate_manifest,&BTreeMap::new(),None)?.into_iter().filter(|p|p.action==update::Action::Conflict).map(|p|(p.path,update::Resolution::Replace)).collect();
let env=Offline(RepackEnv{root,meta_dir:meta});
let outcome=update::apply(&update::Params {root,meta_dir:meta,source,trusted_key:coa_core::signing::EMBEDDED_PUBLIC_KEY,cancel:Default::default(),resolutions:choices,env:&env,fail_after_ops:None},&|stage,pct|println!("{pct}% {stage}"))?;
assert_eq!(outcome.txn.state,update::State::Committed,"{:?}",outcome.txn.message);
backup::with_database(root,|db| {
for (index,mode) in [coa_core::realms::Mode::Coa,coa_core::realms::Mode::Wildcard].into_iter().enumerate() {
let db=db.clone().for_realm(mode);
assert_eq!(players(&db)?,expected[index],"Player data changed in {}",mode.name());
assert!(coa_core::schema_check::check(&db,root)?.is_empty());
assert_eq!(migrations::pending_count(&db,&candidate_manifest.migrations)?,0);
}
Ok(())
})?;
println!("PASS: signed historical package to candidate; missing Wildcard table repaired in both realms; player fields and inventory preserved; schema and startup verified. Launcher isolation was test instrumentation, not packaged UI acceptance.");
Ok(())
}
+1 -1
View File
@@ -29,7 +29,7 @@ fn main() {
let dst = staging.join(db).join(format!("{id}.sql"));
std::fs::create_dir_all(dst.parent().unwrap()).unwrap();
std::fs::write(&dst, &bytes).unwrap();
list.push(Migration { id, db: db.into(), sha256: fsx::sha256_bytes(&bytes), destructive: false });
list.push(Migration { compatible_sha256: vec![], id, db: db.into(), sha256: fsx::sha256_bytes(&bytes), destructive: false });
};
for (kind, dirs) in [("auth", ["db_auth", "pending_db_auth"]), ("characters", ["db_characters", "pending_db_characters"]), ("world", ["db_world", "pending_db_world"])] {
for d in dirs {
+1 -1
View File
@@ -58,7 +58,7 @@ fn main() -> Result<()> {
let path = staged.join(format!("{kind}/manager_realm_fixture.sql"));
std::fs::create_dir_all(path.parent().unwrap())?;
std::fs::write(&path, sql)?;
manifest.migrations.push(Migration { id: "manager_realm_fixture".into(), db: kind.into(), sha256: coa_core::fsx::sha256_file(&path)?, destructive: false });
manifest.migrations.push(Migration { compatible_sha256: vec![], id: "manager_realm_fixture".into(), db: kind.into(), sha256: coa_core::fsx::sha256_file(&path)?, destructive: false });
}
let result = env.migrate(&manifest, &staged)?;
assert!(result.failed.is_none());
+1 -1
View File
@@ -20,7 +20,7 @@ fn main() -> Result<()> {
fsx::atomic_write(&update_tree.join(format!("_migrations/world/{id}.sql")), sql.as_bytes())?;
let options = |kind, version: &str, migrations| BuildOptions { kind, version: version.into(), core_commit: None, built_at: "fixture".into(), part_size: 1 << 20, bots_commit: None, migrations };
let base = package::build(&base_tree, &base_pkg, &options(Kind::Base, "1.0.0", vec![]), &|_| {})?;
let update = package::build(&update_tree, &update_pkg, &options(Kind::Update, "1.0.1", vec![Migration { id: id.into(), db: "world".into(), sha256: fsx::sha256_bytes(sql.as_bytes()), destructive: false }]), &|_| {})?;
let update = package::build(&update_tree, &update_pkg, &options(Kind::Update, "1.0.1", vec![Migration { compatible_sha256: vec![], id: id.into(), db: "world".into(), sha256: fsx::sha256_bytes(sql.as_bytes()), destructive: false }]), &|_| {})?;
// A test-only trust key, unrelated to production signing material.
let key = SigningKey::from_bytes(&[23; 32]);
let public = STANDARD.encode(key.verifying_key().as_bytes());
+1 -1
View File
@@ -33,7 +33,7 @@ fn main() {
let sql = "CREATE TABLE IF NOT EXISTS coa_manager_update_test (id INT PRIMARY KEY); INSERT IGNORE INTO coa_manager_update_test VALUES (1);";
put(&src, "_migrations/world/2026_09_30_00_update_e2e.sql", sql);
let mut m = build(&src, &pkg, &BuildOptions { kind: Kind::Update, version: "0.2.0".into(), core_commit: None, built_at: chrono::Utc::now().to_rfc3339(), part_size: 1 << 20, bots_commit: None, migrations: vec![] }, &|_| {}).unwrap();
m.migrations.push(Migration { id: "2026_09_30_00_update_e2e".into(), db: "world".into(), sha256: fsx::sha256_bytes(sql.as_bytes()), destructive: false });
m.migrations.push(Migration { compatible_sha256: vec![], id: "2026_09_30_00_update_e2e".into(), db: "world".into(), sha256: fsx::sha256_bytes(sql.as_bytes()), destructive: false });
std::fs::write(pkg.join("manifest.json"), serde_json::to_vec_pretty(&m).unwrap()).unwrap();
let key = format!("{}/.coa-manager/signing/manifest-signing.key", std::env::var("USERPROFILE").unwrap());
let seed: [u8; 32] = STANDARD.decode(std::fs::read_to_string(key).unwrap().trim()).unwrap().try_into().unwrap();
@@ -37,7 +37,7 @@ fn exercise(root: &Path) -> Result<()> {
("world", "probe_world", "DROP TABLE manager_recovery_probe; THIS IS INTENTIONALLY INVALID SQL;"),
] {
fsx::atomic_write(&source.join(format!("_migrations/{db}/{id}.sql")), sql.as_bytes())?;
migrations.push(Migration { db: db.into(), id: id.into(), sha256: fsx::sha256_bytes(sql.as_bytes()), destructive: false });
migrations.push(Migration { compatible_sha256: vec![], db: db.into(), id: id.into(), sha256: fsx::sha256_bytes(sql.as_bytes()), destructive: false });
}
let pkg = root.join("fixture-package");
let manifest = package::build(&source, &pkg, &BuildOptions {
@@ -0,0 +1,19 @@
use coa_core::update::{Env, RepackEnv};
use std::path::PathBuf;
fn main() {
let root = PathBuf::from(std::env::args().nth(1).expect("disposable fixture path"));
assert_eq!(std::fs::read(root.join(".release-schema-fixture")).unwrap(), b"disposable release-schema fixture");
let meta = coa_core::registry::metadata_dir_for(&root).unwrap();
let env = RepackEnv { root: &root, meta_dir: &meta };
let result = env.validate();
let _ = coa_core::driver::run(&root, coa_core::driver::Verb::StopAll);
if let Err(error) = result {
eprintln!("{}", error);
for log in ["Core/Logs/auth-console.log", "Core/Logs/world-console.log", "Core/Logs/supervisor.log"] {
eprintln!("{log}:\n{}", coa_core::diag::redact(&coa_core::health::tail(&root.join(log), 8192)));
}
std::process::exit(1);
}
println!("Published server startup validation passed on the disposable fixture");
}
@@ -22,7 +22,7 @@ fn main() -> Result<()> {
let path = old_sql.join(format!("{name}.sql"));
let hash = fsx::sha256_file(&path)?;
db.put(&LedgerRow { db: "characters".into(), id: name.into(), sha256: hash.clone(), status: Status::Applied, error: None, baseline: false })?;
migrations.push(Migration { db: "characters".into(), id: name.into(), sha256: hash, destructive: false });
migrations.push(Migration { compatible_sha256: vec![], db: "characters".into(), id: name.into(), sha256: hash, destructive: false });
}
for (_, tables) in schema_check::WILDCARD_TABLES.iter().filter(|(kind,_)| *kind == "characters") {
for table in *tables { db.query(&format!("DROP TABLE IF EXISTS acore_characters.`{table}`;"))?; }
@@ -33,7 +33,7 @@ fn main() -> Result<()> {
let files = release_schema::collect(empty_core.path(), None, Some(&repairs))?;
assert_eq!(files.len(), 1);
let repair = &files[0];
migrations.push(Migration { db: repair.db.clone(), id: repair.id.clone(), sha256: repair.sha256.clone(), destructive: false });
migrations.push(Migration { compatible_sha256: vec![], db: repair.db.clone(), id: repair.id.clone(), sha256: repair.sha256.clone(), destructive: false });
let staged = tree.path().join("sql/characters");
fsx::atomic_write(&staged.join(format!("{}.sql", repair.id)), &std::fs::read(&repair.abs)?)?;
let report = migrations::apply_pending(&db, &migrations, &tree.path().join("sql"), &|| Ok("disposable fixture".into()))?;
+64 -7
View File
@@ -51,6 +51,8 @@ pub struct Component {
pub sha256: Option<String>,
pub tables: Option<usize>,
pub files: Option<Vec<String>>,
#[serde(default)]
pub file_sha256: std::collections::BTreeMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -91,7 +93,9 @@ pub fn list(meta: &Path) -> Vec<RecoveryPoint> {
}
pub fn get(meta: &Path, id: &str) -> Result<RecoveryPoint> {
fsx::read_json(&point_dir(meta, id)?.join("backup.json")).map_err(|_| Error::Invalid(format!("backup {id} was not found")))
let point: RecoveryPoint = fsx::read_json(&fsx::ensure_within(meta, &point_dir(meta, id)?.join("backup.json"))?).map_err(|_| Error::Invalid(format!("backup {id} was not found or its metadata is damaged")))?;
if point.id != id || point.schema != 1 { return Err(Error::Invalid(format!("Backup {id} has inconsistent identity or an unsupported schema."))); }
Ok(point)
}
/// Files that make up "configuration": everything a user or the Manager may have changed, minus secrets.
@@ -139,13 +143,16 @@ fn copy_configs(root: &Path, dir: &Path) -> Result<Component> {
let files = config_files(root);
let target = dir.join("files");
let mut bytes = 0;
let mut file_sha256 = std::collections::BTreeMap::new();
for rel in &files {
let src = fsx::safe_join(root, rel)?;
let dst = fsx::safe_join(&target, rel)?;
fs::create_dir_all(dst.parent().unwrap())?;
bytes += fs::copy(&src, &dst)?;
let content = fs::read(&src)?;
fsx::atomic_write(&dst, &content)?;
bytes += content.len() as u64;
file_sha256.insert(rel.clone(), fsx::sha256_bytes(&content));
}
Ok(Component { name: "configs".into(), path: "files".into(), bytes, sha256: None, tables: None, files: Some(files) })
Ok(Component { name: "configs".into(), path: "files".into(), bytes, sha256: None, tables: None, files: Some(files), file_sha256 })
}
/// Make sure the database is up for `f`. If we had to start it (and nothing else is running), stop it again.
@@ -215,7 +222,7 @@ pub fn create(root: &Path, meta: &Path, kind: Kind, trigger: Trigger, label: Opt
let tables = db.tables(schema)?.len();
let file = format!("{name}.sql.zst");
let (bytes, sha) = db.dump_to(schema, &partial.join(&file))?;
Ok(Component { name, path: file, bytes, sha256: Some(sha), tables: Some(tables), files: None })
Ok(Component { name, path: file, bytes, sha256: Some(sha), tables: Some(tables), files: None, file_sha256: Default::default() })
})?;
components.push(component);
}
@@ -255,6 +262,7 @@ pub fn create(root: &Path, meta: &Path, kind: Kind, trigger: Trigger, label: Opt
/// Keep the newest `keep` automatic recovery points; manual and safety ones are never pruned.
pub fn prune_automatic(meta: &Path, keep: usize) {
if crate::update::ensure_recovered(meta).is_err() { return; }
let autos: Vec<_> = list(meta).into_iter().filter(|p| p.trigger == Trigger::Automatic).collect();
for p in autos.into_iter().skip(keep) {
if let Ok(dir) = point_dir(meta, &p.id) {
@@ -273,8 +281,21 @@ pub fn verify(meta: &Path, id: &str) -> Result<VerifyReport> {
let point = get(meta, id)?;
let dir = point_dir(meta, id)?;
let mut problems = Vec::new();
let mut names = std::collections::BTreeSet::new();
let mut schemas = std::collections::BTreeSet::new();
for c in &point.components {
let path = dir.join(&c.path);
if !names.insert(&c.name) { problems.push(format!("{} appears more than once", c.name)); }
let path = fsx::ensure_within(&dir, &fsx::safe_join(&dir, &c.path)?)?;
if c.name != "configs" && (c.sha256.is_none() || c.tables.is_none()) { problems.push(format!("{} lacks database integrity metadata", c.name)); }
if c.name == "configs" {
if c.sha256.is_some() || c.files.is_none() { problems.push("configuration integrity metadata is inconsistent".into()); }
} else {
let schema = if c.name.contains('-') || c.name == "playerbots" { db::schema_of(&c.name) } else { point.realm.schema(&c.name) };
match schema {
Ok(schema) if schemas.insert(schema) => {}
_ => problems.push(format!("{} has an unknown or duplicate database target", c.name)),
}
}
match (&c.sha256, &c.files) {
(Some(sha), _) => match fsx::sha256_file(&path) {
Ok(actual) if actual.eq_ignore_ascii_case(sha) => {}
@@ -283,12 +304,16 @@ pub fn verify(meta: &Path, id: &str) -> Result<VerifyReport> {
},
(None, Some(files)) => {
for f in files {
if !c.file_sha256.is_empty() && !c.file_sha256.contains_key(f) { problems.push(format!("configuration file {f} lacks its checksum")); }
if !fsx::safe_join(&path, f).map(|p| p.is_file()).unwrap_or(false) {
problems.push(format!("configuration file {f} is missing"));
} else if let Some(expected) = c.file_sha256.get(f) {
let file = fsx::ensure_within(&dir, &fsx::safe_join(&path, f)?)?;
if fsx::sha256_file(&file)?.as_str() != expected { problems.push(format!("configuration file {f} is damaged")); }
}
}
}
_ => {}
_ => problems.push(format!("{} lacks an integrity inventory", c.name)),
}
}
Ok(VerifyReport { ok: problems.is_empty(), problems })
@@ -296,6 +321,8 @@ pub fn verify(meta: &Path, id: &str) -> Result<VerifyReport> {
/// Delete one recovery point (its own folder only).
pub fn delete(meta: &Path, id: &str) -> Result<()> {
let _lock = crate::update::operation_lock(meta)?;
crate::update::ensure_recovered(meta)?;
if crate::update::unfinished(meta).is_some_and(|t| t.recovery_point.as_deref() == Some(id)) {
return Err(Error::Invalid("This recovery point is required by an unfinished update and cannot be deleted.".into()));
}
@@ -405,6 +432,36 @@ mod tests {
(dir, root, meta)
}
#[test]
fn backup_deletion_obeys_the_installation_lock() {
let (_d, root, meta) = setup();
let point = create(&root, &meta, Kind::Config, Trigger::Manual, None, &|_| {}).unwrap();
let lock = crate::update::operation_lock(&meta).unwrap();
assert!(delete(&meta, &point.id).is_err());
assert!(get(&meta, &point.id).is_ok());
drop(lock);
delete(&meta, &point.id).unwrap();
assert!(get(&meta, &point.id).is_err());
}
#[test]
fn damaged_configuration_is_detected_before_restore_and_copies_are_retained() {
let (_d, root, meta) = setup();
let point = create(&root, &meta, Kind::Config, Trigger::Automatic, None, &|_| {}).unwrap();
let file = point_dir(&meta, &point.id).unwrap().join("files/Core/configs/worldserver.conf");
fs::write(&file, b"corrupted").unwrap();
assert!(!verify(&meta, &point.id).unwrap().ok);
let original = fs::read(root.join("Core/configs/worldserver.conf")).unwrap();
assert!(restore_configs(&root, &meta, &point.id).is_err());
assert_eq!(fs::read(root.join("Core/configs/worldserver.conf")).unwrap(), original);
assert_eq!(list(&meta).len(), 1);
fs::create_dir_all(meta.join("updates/broken")).unwrap();
fs::write(meta.join("updates/broken/txn.json"), b"{damaged").unwrap();
assert!(delete(&meta, &point.id).is_err());
prune_automatic(&meta, 0);
assert!(file.exists());
}
#[test]
fn config_backup_excludes_secrets_and_clutter_and_restores_byte_exact() {
let (_d, root, meta) = setup();
+1 -1
View File
@@ -181,7 +181,7 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
if let Some(b) = p.bots {
sql.extend(collect_bots_sql(b)?);
}
let migrations: Vec<_> = sql.iter().map(|f| crate::manifest::Migration { id: f.id.clone(), db: f.db.clone(), sha256: f.sha256.clone(), destructive: false }).collect();
let migrations: Vec<_> = sql.iter().map(|f| crate::manifest::Migration { compatible_sha256: vec![], id: f.id.clone(), db: f.db.clone(), sha256: f.sha256.clone(), destructive: false }).collect();
let staging = std::env::temp_dir().join("coa-cleanbase-sql");
let _ = fs::remove_dir_all(&staging);
for f in &sql {
+1 -1
View File
@@ -180,7 +180,7 @@ fn backup_dir(meta: &Path) -> PathBuf {
meta.join("backups").join("client")
}
fn host_ok(h: &str) -> bool {
pub fn host_ok(h: &str) -> bool {
!h.is_empty() && h.len() <= 253 && h.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '-' | ':')) && !h.starts_with('-')
}
+5 -1
View File
@@ -199,6 +199,7 @@ pub fn export_package(root: &Path, meta_dir: &Path, manager_log: &Path, meta: &I
"manager": crate::MANAGER_VERSION,
"core": meta.core,
"bots": meta.bots,
"squid_bots": crate::squid::release(root),
"kind": meta.kind,
"layout": meta.layout,
"checks": report.checks,
@@ -323,6 +324,8 @@ real error
let d = tempfile::tempdir().unwrap();
let root = d.path().join("srv");
layout::testkit::fake_repack(&root);
fs::create_dir_all(root.join("Extras/SquidPlayerbots")).unwrap();
fs::write(root.join("Extras/SquidPlayerbots/release.json"), r#"{"tag":"v1.8","commit":"48c4786a","password":"upstream-secret"}"#).unwrap();
fs::write(root.join("Core/Logs/Errors.log"), "boom\nDatabase password=hunter2 rejected\n").unwrap();
fs::write(root.join("Core/configs/worldserver.conf"), "LoginDatabaseInfo = \"127.0.0.1;3307;acore;SECRETPW;auth\"\nRate.XP.Kill = 1\n").unwrap();
let meta_dir = d.path().join("srv.manager");
@@ -340,6 +343,7 @@ real error
all.push_str(&s);
}
assert!(all.contains("boom") && all.contains("Rate.XP.Kill"), "keys and ordinary log lines are included");
assert!(!all.contains("hunter2") && !all.contains("SECRETPW"));
assert!(all.contains("v1.8") && all.contains("48c4786a"));
assert!(!all.contains("hunter2") && !all.contains("SECRETPW") && !all.contains("upstream-secret"));
}
}
+102 -3
View File
@@ -31,8 +31,9 @@ impl Verb {
}
}
fn timeout(self) -> Duration {
fn timeout(self, root: &Path) -> Duration {
match self {
Verb::StartAll | Verb::StartWorld if squid_enabled(root) => Duration::from_secs(2700),
Verb::StartAll | Verb::StartWorld => Duration::from_secs(420),
Verb::StartMysql => Duration::from_secs(120),
Verb::StopAll => Duration::from_secs(240),
@@ -40,6 +41,14 @@ impl Verb {
}
}
fn squid_enabled(root: &Path) -> bool {
let active = root.join("Core/configs/modules/playerbots.conf");
let path = if active.exists() { active } else { root.join("Core/configs/modules/playerbots.conf.dist") };
std::fs::read(path).ok().and_then(|bytes| crate::config::parser::ConfFile::parse_bytes(&bytes).ok())
.is_some_and(|config| config.get("AiPlayerbot.Enabled").is_none_or(|value|
!matches!(value.trim().trim_matches('"').to_ascii_lowercase().as_str(), "0" | "false" | "no" | "off")))
}
#[derive(Debug, Clone, Serialize)]
pub struct DriverOutcome {
pub ok: bool,
@@ -114,8 +123,22 @@ fn run_inner(root: &Path, verb: Verb, validating_update: bool) -> Result<DriverO
}
if matches!(verb, Verb::StartAll | Verb::StartWorld) { crate::modules::ensure_bot_exclusivity(&root)?; }
let (python, script) = launcher(&root)?;
let original = std::fs::read_to_string(&script)?;
let patched = patch_launcher_imports(&original)?;
if original != patched {
fsx::atomic_write(&script, patched.as_bytes())?;
if let Ok(dir) = crate::registry::metadata_dir_for(&root) {
if let Ok((_, mut meta)) = crate::registry::MetaDir::open(&dir) {
if meta.original_hashes.get("Scripts/manage.py") == Some(&fsx::sha256_bytes(original.as_bytes())) {
meta.original_hashes.insert("Scripts/manage.py".into(), fsx::sha256_bytes(patched.as_bytes()));
fsx::atomic_write_json(&dir.join("install.json"), &meta)?;
}
}
}
}
let mut cmd = Command::new(&python);
cmd.arg("-B").arg(&script).arg(verb.arg()).current_dir(&root).stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped());
cmd.arg("-B").arg("-c").arg(LAUNCH_SCRIPT).arg(&script).arg(verb.arg())
.current_dir(&root).stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped());
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
@@ -135,7 +158,7 @@ fn run_inner(root: &Path, verb: Verb, validating_update: bool) -> Result<DriverO
let _ = stderr.read_to_string(&mut s);
s
});
let deadline = Instant::now() + verb.timeout();
let deadline = Instant::now() + verb.timeout(&root);
let status = loop {
if let Some(st) = child.try_wait()? {
break Some(st);
@@ -169,10 +192,65 @@ fn run_inner(root: &Path, verb: Verb, validating_update: bool) -> Result<DriverO
Ok(DriverOutcome { ok, exit_code, code, human: code.map(ErrorCode::human), output })
}
const LAUNCH_SCRIPT: &str = "import runpy,sys;from pathlib import Path;script=sys.argv[1];sys.path.insert(0,str(Path(script).resolve().parent));sys.argv=sys.argv[1:];runpy.run_path(script,run_name='__main__')";
pub(crate) fn patch_launcher_imports(text: &str) -> Result<String> {
let line = "sys.path.insert(0, str(Path(__file__).resolve().parent))";
if !text.contains("from squid_playerbots import") || text.contains(line) { return Ok(text.into()); }
let root = "ROOT = Path(__file__).resolve().parents[1]";
if !text.contains(root) || !text.lines().any(|line| line.trim() == "import sys") {
return Err(Error::Invalid("The server launcher cannot load its integration scripts. Repair its program files.".into()));
}
Ok(text.replacen(root, &format!("{root}\n{line}"), 1))
}
pub(crate) fn launcher_matches(signed: &str, actual: &[u8]) -> bool {
if signed.as_bytes() == actual { return true; }
if patch_launcher_imports(signed).is_ok_and(|s| s.as_bytes() == actual) { return true; }
crate::realms::patch_launcher(signed).is_ok_and(|s| s.as_bytes() == actual
|| patch_launcher_imports(&s).is_ok_and(|p| p.as_bytes() == actual))
}
/// Recover legacy metadata only when undoing supported Manager edits reproduces the recorded hash.
pub(crate) fn launcher_matches_recorded(recorded: &str, actual: &[u8]) -> bool {
let Ok(text) = std::str::from_utf8(actual) else { return false; };
let without_import = text.replacen(
"ROOT = Path(__file__).resolve().parents[1]\nsys.path.insert(0, str(Path(__file__).resolve().parent))",
"ROOT = Path(__file__).resolve().parents[1]", 1,
);
for candidate in [Some(without_import.clone()), crate::realms::unpatch_launcher(&without_import)].into_iter().flatten() {
if crate::fsx::sha256_bytes(candidate.as_bytes()).eq_ignore_ascii_case(recorded)
&& launcher_matches(&candidate, actual) { return true; }
}
false
}
pub(crate) fn startup_failure(root: &Path, started: &DriverOutcome) -> String {
let code = started.code.filter(|c| *c != ErrorCode::Unknown)
.or_else(|| crate::health::diagnose_installation(root));
let title = code.map(|c| c.human().title).unwrap_or("The server did not become ready");
let output = crate::diag::redact(&started.output);
let lines: Vec<_> = output.lines().rev().take(12).collect();
if lines.is_empty() { title.into() }
else { format!("{title}\n{}", lines.into_iter().rev().collect::<Vec<_>>().join("\n")) }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn large_squid_provisioning_has_time_to_finish_without_extending_shutdown() {
let folder = tempfile::tempdir().unwrap();
let modules = folder.path().join("Core/configs/modules");
std::fs::create_dir_all(&modules).unwrap();
std::fs::write(modules.join("playerbots.conf.dist"), "AiPlayerbot.Enabled = 1\n").unwrap();
assert_eq!(Verb::StartAll.timeout(folder.path()), Duration::from_secs(2700));
assert_eq!(Verb::StopAll.timeout(folder.path()), Duration::from_secs(240));
std::fs::write(modules.join("playerbots.conf"), "AiPlayerbot.Enabled = 0\n").unwrap();
assert_eq!(Verb::StartWorld.timeout(folder.path()), Duration::from_secs(420));
}
#[test]
fn translates_known_launcher_messages() {
assert_eq!(translate("RuntimeError: Port 8085 is already used. Stop the other server"), ErrorCode::PortInUse);
@@ -187,4 +265,25 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
assert!(run(dir.path(), Verb::StartAll).is_err());
}
#[test]
fn startup_failure_keeps_the_launcher_reason_without_secrets() {
let dir = tempfile::tempdir().unwrap();
let started = DriverOutcome { ok: false, exit_code: Some(1), code: Some(ErrorCode::Unknown),
human: Some(ErrorCode::Unknown.human()),
output: "appPassword=private\nModuleNotFoundError: No module named 'squid_playerbots'".into() };
let reason = startup_failure(dir.path(), &started);
assert!(reason.contains("ModuleNotFoundError"));
assert!(!reason.contains("private"));
assert!(!reason.contains("Something went wrong"));
}
#[test]
fn launcher_import_fix_is_idempotent_and_retains_other_code() {
let text = "import sys\nROOT = Path(__file__).resolve().parents[1]\nfrom squid_playerbots import validate_bots\ncustom = 42\n";
let fixed = patch_launcher_imports(text).unwrap();
assert!(fixed.contains("sys.path.insert(0, str(Path(__file__).resolve().parent))"));
assert!(fixed.ends_with("custom = 42\n"));
assert_eq!(patch_launcher_imports(&fixed).unwrap(), fixed);
}
}
+49 -3
View File
@@ -123,7 +123,7 @@ pub fn atomic_write(path: &Path, bytes: &[u8]) -> Result<()> {
let tmp = parent.join(format!(
".{}.{}.tmp",
path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default(),
std::process::id()
uuid::Uuid::new_v4().simple()
));
let write = || -> std::io::Result<()> {
let mut f = OpenOptions::new().write(true).create_new(true).open(&tmp)?;
@@ -135,13 +135,41 @@ pub fn atomic_write(path: &Path, bytes: &[u8]) -> Result<()> {
let _ = fs::remove_file(&tmp);
return Err(e.into());
}
if let Err(e) = fs::rename(&tmp, path) {
if let Err(e) = durable_replace(&tmp, path) {
let _ = fs::remove_file(&tmp);
return Err(e.into());
}
Ok(())
}
/// The temporary file must already be flushed, on the same volume as the destination.
pub(crate) fn durable_replace(from: &Path, to: &Path) -> std::io::Result<()> {
#[cfg(windows)]
{
use std::os::windows::ffi::OsStrExt;
use windows_sys::Win32::Storage::FileSystem::{MoveFileExW, MOVEFILE_REPLACE_EXISTING, MOVEFILE_WRITE_THROUGH};
fn wide(path: &Path) -> std::io::Result<Vec<u16>> {
let absolute = std::path::absolute(path)?;
let text = absolute.as_os_str().to_string_lossy().replace('/', "\\");
let extended = if text.starts_with("\\\\?\\") { text }
else if let Some(unc) = text.strip_prefix("\\\\") { format!("\\\\?\\UNC\\{unc}") }
else { format!("\\\\?\\{text}") };
Ok(std::ffi::OsStr::new(&extended).encode_wide().chain(Some(0)).collect())
}
let src = wide(from)?;
let dst = wide(to)?;
if unsafe { MoveFileExW(src.as_ptr(), dst.as_ptr(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) } == 0 {
return Err(std::io::Error::last_os_error());
}
Ok(())
}
#[cfg(not(windows))]
{
fs::rename(from, to)?;
File::open(to.parent().unwrap())?.sync_all()
}
}
pub fn atomic_write_json<T: serde::Serialize>(path: &Path, value: &T) -> Result<()> {
let mut bytes = serde_json::to_vec_pretty(value)?;
bytes.push(b'\n');
@@ -174,7 +202,8 @@ pub fn sha256_bytes(bytes: &[u8]) -> String {
/// Free bytes on the volume that holds `path` (or its nearest existing ancestor).
pub fn free_space(path: &Path) -> Result<u64> {
let mut cursor = Some(path);
let path = std::path::absolute(path)?;
let mut cursor = Some(path.as_path());
while let Some(p) = cursor {
if p.exists() {
return Ok(fs4::available_space(p)?);
@@ -198,6 +227,16 @@ pub fn require_space(path: &Path, needed: u64) -> Result<()> {
mod tests {
use super::*;
#[test]
fn durable_replacement_handles_long_transaction_backup_paths() {
let dir = tempfile::tempdir().unwrap();
let parent = dir.path().join("a".repeat(90)).join("b".repeat(90));
let path = parent.join("configuration-with-a-long-name.template");
atomic_write(&path, b"old").unwrap();
atomic_write(&path, b"new").unwrap();
assert_eq!(fs::read(&path).unwrap(), b"new");
}
#[test]
fn safe_join_accepts_normal_and_rejects_traversal() {
let root = Path::new("C:/srv");
@@ -281,4 +320,11 @@ mod tests {
let dir = tempfile::tempdir().unwrap();
assert!(matches!(require_space(dir.path(), u64::MAX / 2), Err(Error::InsufficientSpace { .. })));
}
#[test]
fn free_space_resolves_a_new_relative_directory() {
let path = Path::new("coa-schema-fixture-not-created").join("nested");
assert!(!path.exists());
assert!(free_space(&path).unwrap() > 0);
}
}
+1
View File
@@ -315,6 +315,7 @@ pub fn scan(root: &Path) -> Result<ScanReport> {
(None, None)
};
if crate::squid::imported_repack(&root) { notes.push("import.squidRepackWarning".into()); }
Ok(ScanReport {
path: root.to_string_lossy().into_owned(),
classification,
+3
View File
@@ -3,6 +3,7 @@ pub mod backup;
pub mod cleanbase;
pub mod companions;
pub mod client;
pub mod remote_client;
pub mod clientdl;
pub mod config;
pub mod console;
@@ -45,3 +46,5 @@ pub mod srp6;
pub use error::{Error, ErrorCode, Result};
pub const MANAGER_VERSION: &str = env!("CARGO_PKG_VERSION");
pub mod squid;
+7
View File
@@ -48,6 +48,8 @@ pub struct FileEntry {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Migration {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub compatible_sha256: Vec<String>,
pub id: String,
pub db: String,
pub sha256: String,
@@ -134,6 +136,11 @@ impl Manifest {
if parse_version(&self.min_manager_version).is_none() {
return bad(format!("bad minManagerVersion {:?}", self.min_manager_version));
}
for migration in &self.migrations {
if !is_sha256(&migration.sha256) || migration.compatible_sha256.iter().any(|h| !is_sha256(h) || h == &"0".repeat(64)) {
return bad(format!("{}: invalid migration checksum compatibility", migration.id));
}
}
for (label, rev) in [("core", Some(&self.core)), ("bots", self.bots.as_ref())] {
if let Some(Revision { commit: Some(c) }) = rev {
if !is_commit(c) {
+110 -21
View File
@@ -35,6 +35,7 @@ pub struct LedgerRow {
/// Storage for the ledger and the ability to run a SQL file; implemented by the real database and by tests.
pub trait Store {
fn load(&self) -> Result<Vec<LedgerRow>>;
fn load_readonly(&self) -> Result<Vec<LedgerRow>> { self.load() }
fn put(&self, row: &LedgerRow) -> Result<()>;
fn run_file(&self, schema: &str, file: &Path) -> Result<()>;
}
@@ -52,7 +53,13 @@ impl Store for Db {
self.query(&format!(
"CREATE TABLE IF NOT EXISTS `{LEDGER_SCHEMA}`.`{LEDGER_TABLE}` (`db` VARCHAR(32) NOT NULL, `id` VARCHAR(190) NOT NULL, `sha256` CHAR(64) NOT NULL, `status` VARCHAR(16) NOT NULL, `applied_at` DATETIME NOT NULL, `error` TEXT NULL, `baseline` TINYINT NOT NULL DEFAULT 0, PRIMARY KEY (`db`,`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"
))?;
let out = self.query(&format!("SELECT `db`,`id`,`sha256`,`status`,`baseline`,COALESCE(HEX(`error`),'') FROM `{LEDGER_SCHEMA}`.`{LEDGER_TABLE}` ORDER BY `db`,`id`;"))?;
self.load_readonly()
}
fn load_readonly(&self) -> Result<Vec<LedgerRow>> {
let out = if self.tables(LEDGER_SCHEMA)?.iter().any(|name| name == LEDGER_TABLE) {
self.query(&format!("SELECT `db`,`id`,`sha256`,`status`,`baseline`,COALESCE(HEX(`error`),'') FROM `{LEDGER_SCHEMA}`.`{LEDGER_TABLE}` ORDER BY `db`,`id`;"))?
} else { String::new() };
let mut rows = Vec::new();
// Files the core's own updater (or whoever prepared this database) already recorded count as applied.
for (kind, schema) in db::SCHEMAS {
@@ -149,6 +156,50 @@ fn recorded<'a>(rows: &'a [LedgerRow], m: &Migration) -> Option<&'a LedgerRow> {
fn hash_changed(row: &LedgerRow, m: &Migration) -> bool {
row.status == Status::Applied && row.sha256 != "0".repeat(64) && !row.sha256.eq_ignore_ascii_case(&m.sha256)
&& !m.compatible_sha256.iter().any(|hash| hash.eq_ignore_ascii_case(&row.sha256))
}
/// Inspect recorded history without creating a ledger or executing migrations.
pub fn preflight(store: &dyn Store, list: &[Migration]) -> Result<()> {
check_history(&store.load_readonly()?, list)
}
pub fn pending_count(store: &dyn Store, list: &[Migration]) -> Result<usize> {
let rows = store.load_readonly()?;
check_history(&rows, list)?;
Ok(list.iter().filter(|m| recorded(&rows, m).is_none_or(|r| r.status != Status::Applied)).count())
}
fn verified_file(m: &Migration, dir: &Path) -> Result<(&'static str, std::path::PathBuf, bool)> {
if !ident_ok(&m.id) { return Err(Error::InvalidManifest(format!("migration id {:?} is not allowed", m.id))); }
let schema = db::schema_of(&m.db)?;
let path = fsx::safe_join(dir, &format!("{}/{}.sql", m.db, m.id))?;
let bytes = std::fs::read(&path).map_err(|_| Error::Invalid(format!("migration file {} is missing", m.id)))?;
let actual = fsx::sha256_bytes(&bytes);
if !actual.eq_ignore_ascii_case(&m.sha256) { return Err(Error::HashMismatch { path: path.display().to_string(), expected: m.sha256.clone(), actual }); }
Ok((schema, path, m.destructive || looks_destructive(&String::from_utf8_lossy(&bytes))))
}
/// Check every migration artifact, including applied history, before replacing server files.
pub fn verify_files(list: &[Migration], dir: &Path) -> Result<()> {
let mut seen = std::collections::BTreeSet::new();
for m in list {
if !seen.insert((&m.db, &m.id)) { return Err(Error::InvalidManifest(format!("duplicate migration {} ({})", m.id, m.db))); }
verified_file(m, dir)?;
}
Ok(())
}
fn check_history(rows: &[LedgerRow], list: &[Migration]) -> Result<()> {
for m in list {
if recorded(rows, m).is_some_and(|r| matches!(r.status, Status::Running | Status::Failed)) {
return Err(Error::Invalid(format!("Database update {} ({}) failed or was interrupted and may be partially applied. Restore its recovery point before retrying.", m.id, m.db)));
}
if recorded(rows, m).is_some_and(|r| hash_changed(r, m)) {
return Err(Error::Invalid(format!("Applied database update {} ({}) has a different checksum. A new migration is required; it was not replayed.", m.id, m.db)));
}
}
Ok(())
}
/// Record migrations as already present without running them (adopting an existing server whose database
@@ -178,14 +229,7 @@ pub struct ApplyReport {
pub fn apply_pending(store: &dyn Store, list: &[Migration], dir: &Path, snapshot: &dyn Fn() -> Result<String>) -> Result<ApplyReport> {
let rows = store.load()?;
// The list order is the release's order of application (released updates, then pending, then modules).
for m in list {
if recorded(&rows, m).is_some_and(|r| matches!(r.status, Status::Running | Status::Failed)) {
return Err(Error::Invalid(format!("Database update {} ({}) failed or was interrupted and may be partially applied. Restore its recovery point before retrying.", m.id, m.db)));
}
if recorded(&rows, m).is_some_and(|r| hash_changed(r, m)) {
return Err(Error::Invalid(format!("Applied database update {} ({}) has a different checksum. A new migration is required; it was not replayed.", m.id, m.db)));
}
}
check_history(&rows, list)?;
let todo: Vec<&Migration> = list.iter().filter(|m| recorded(&rows, m).is_none_or(|r| r.status != Status::Applied)).collect();
tracing::info!(total = list.len(), pending = todo.len(), skipped = list.len() - todo.len(), "database migration plan");
@@ -193,17 +237,8 @@ pub fn apply_pending(store: &dyn Store, list: &[Migration], dir: &Path, snapshot
let mut files = Vec::new();
let mut any_destructive = false;
for m in &todo {
if !ident_ok(&m.id) {
return Err(Error::InvalidManifest(format!("migration id {:?} is not allowed", m.id)));
}
let schema = db::schema_of(&m.db)?;
let path = fsx::safe_join(dir, &format!("{}/{}.sql", m.db, m.id))?;
let bytes = std::fs::read(&path).map_err(|_| Error::Invalid(format!("migration file {} is missing", m.id)))?;
let actual = fsx::sha256_bytes(&bytes);
if !actual.eq_ignore_ascii_case(&m.sha256) {
return Err(Error::HashMismatch { path: path.display().to_string(), expected: m.sha256.clone(), actual });
}
any_destructive |= m.destructive || looks_destructive(&String::from_utf8_lossy(&bytes));
let (schema, path, destructive) = verified_file(m, dir)?;
any_destructive |= destructive;
files.push((*m, schema, path));
}
@@ -273,7 +308,7 @@ mod tests {
for (db, id, sql) in files {
std::fs::create_dir_all(d.path().join(db)).unwrap();
std::fs::write(d.path().join(db).join(format!("{id}.sql")), sql).unwrap();
list.push(Migration { id: id.to_string(), db: db.to_string(), sha256: fsx::sha256_bytes(sql.as_bytes()), destructive: false });
list.push(Migration { compatible_sha256: vec![], id: id.to_string(), db: db.to_string(), sha256: fsx::sha256_bytes(sql.as_bytes()), destructive: false });
}
(d, list)
}
@@ -304,6 +339,60 @@ mod tests {
assert!(store.ran.borrow().is_empty());
}
#[test]
fn staged_files_reject_missing_corrupt_duplicate_and_invalid_migrations() {
let (dir, list) = setup(&[("characters", "repair", "SELECT 1;\n")]);
verify_files(&list, dir.path()).unwrap();
let mut bad = list.clone();
bad[0].id = "../outside".into();
assert!(verify_files(&bad, dir.path()).is_err());
bad = list.clone();
bad.push(list[0].clone());
assert!(verify_files(&bad, dir.path()).is_err());
std::fs::write(dir.path().join("characters/repair.sql"), b"SELECT 2;\n").unwrap();
assert!(verify_files(&list, dir.path()).is_err());
std::fs::remove_file(dir.path().join("characters/repair.sql")).unwrap();
assert!(verify_files(&list, dir.path()).is_err());
}
#[test]
fn preflight_uses_readonly_history_and_rejects_conflicts_without_writes() {
struct ReadOnly<'a>(&'a Mem);
impl Store for ReadOnly<'_> {
fn load(&self) -> Result<Vec<LedgerRow>> { panic!("preflight must use readonly access") }
fn load_readonly(&self) -> Result<Vec<LedgerRow>> { self.0.load() }
fn put(&self, _: &LedgerRow) -> Result<()> { panic!("preflight must not rewrite history") }
fn run_file(&self, _: &str, _: &Path) -> Result<()> { panic!("preflight must not run SQL") }
}
let (_d, list) = setup(&[("characters", "repair", "SELECT 1;\n")]);
for state in [Status::Applied, Status::Running, Status::Failed] {
let store = Mem::default();
store.rows.borrow_mut().push(LedgerRow { db: "characters".into(), id: "repair".into(), sha256: "a".repeat(64), status: state, error: None, baseline: false });
assert!(preflight(&ReadOnly(&store), &list).is_err());
assert_eq!(store.rows.borrow()[0].sha256, "a".repeat(64));
assert_eq!(store.rows.borrow()[0].status, state);
}
}
#[test]
fn published_compatibility_preserves_history_and_never_replays_sql() {
let (d, mut list) = setup(&[("characters", "repair", "SELECT 1;\n")]);
let store = Mem::default();
let old = fsx::sha256_bytes(b"SELECT 1;\r\n");
store.rows.borrow_mut().push(LedgerRow { db: "characters".into(), id: "repair".into(), sha256: old.clone(), status: Status::Applied, error: None, baseline: false });
assert!(apply_pending(&store, &list, d.path(), &no_snapshot).is_err());
list[0].compatible_sha256.push(old.clone());
assert_eq!(status(&store, &list).unwrap()[0].status, Status::Applied);
assert!(apply_pending(&store, &list, d.path(), &no_snapshot).unwrap().applied.is_empty());
assert!(store.ran.borrow().is_empty());
assert_eq!(store.rows.borrow()[0].sha256, old);
store.rows.borrow_mut()[0].status = Status::Running;
assert!(apply_pending(&store, &list, d.path(), &no_snapshot).is_err());
store.rows.borrow_mut()[0].status = Status::Failed;
assert!(apply_pending(&store, &list, d.path(), &no_snapshot).is_err());
assert!(store.ran.borrow().is_empty());
}
#[test]
fn applies_in_order_once_and_records_the_ledger() {
let (d, list) = setup(&[("world", "2026_09_01_00_a", "CREATE TABLE t (id INT);"), ("world", "2026_09_02_00_b", "ALTER TABLE t ADD c INT;")]);
+77 -4
View File
@@ -87,6 +87,7 @@ fn truthy(v: &str) -> bool {
pub struct ModuleView {
pub id: String,
pub name: String,
pub version: Option<String>,
pub description: BTreeMap<String, String>,
pub repo: String,
/// The module's configuration is present on this server (otherwise it is not part of this server build).
@@ -137,7 +138,11 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec<ModuleView> {
!e.switchable || read(&conf).or_else(|| read(&dist)).and_then(|c| c.get(&e.enable_key).map(truthy)).unwrap_or(e.default_on)
};
let blocked = wildcard && matches!(e.id.as_str(), "companions" | "playerbots");
let version = if e.id == "playerbots" { crate::squid::release(root).map(|release| {
[release.tag, release.commit.map(|commit| commit.chars().take(8).collect())].into_iter().flatten().collect::<Vec<_>>().join(" · ")
}) } else { None };
ModuleView {
version,
compatibility: if blocked { "unsupported" } else if wildcard && e.id != "client-compat" { "experimental" } else { "compatible" }.into(),
id: e.id,
name: e.name,
@@ -243,13 +248,14 @@ fn set_enabled_in(cat: &[Entry], root: &Path, meta: &Path, id: &str, on: bool) -
Ok(())
}
#[derive(Debug, Serialize, PartialEq, Eq)]
#[derive(Debug, Serialize, PartialEq)]
pub struct Setting {
pub key: String,
pub value: String,
pub default: Option<String>,
/// The documentation the module ships above the setting.
pub doc: String,
pub field: Option<crate::squid::Field>,
}
/// Every active setting of the module with its current value, its documented default and its description.
@@ -263,6 +269,7 @@ fn settings_in(cat: &[Entry], root: &Path, id: &str) -> Result<Vec<Setting>> {
let conf = dir(root).join(&name);
let dist = read(&dir(root).join(format!("{name}.dist")));
let active = read(&conf).or_else(|| dist.clone()).ok_or_else(|| Error::Invalid("This module is not part of this server.".into()))?;
let fields = if id == "playerbots" { crate::squid::fields(root)? } else { Default::default() };
let mut effective = active.clone();
if let Some(defaults) = &dist {
for (key, value) in defaults.entries() {
@@ -275,8 +282,9 @@ fn settings_in(cat: &[Entry], root: &Path, id: &str) -> Result<Vec<Setting>> {
.entries()
.map(|(k, v)| Setting {
key: k.to_string(),
value: v.to_string(),
default: dist.as_ref().and_then(|d| d.get(k)).map(str::to_string),
value: fields.get(k).and_then(|field| field.default_if_missing.as_ref()).filter(|_| active.get(k).is_none()).and_then(crate::squid::scalar).unwrap_or_else(|| v.to_string()),
default: fields.get(k).and_then(|field| crate::squid::scalar(&field.default)).or_else(|| dist.as_ref().and_then(|d| d.get(k)).map(str::to_string)),
field: fields.get(k).cloned(),
doc: dist.as_ref().map(|d| d.doc_for(k)).filter(|d| !d.is_empty()).unwrap_or_else(|| active.doc_for(k)).join(" "),
})
.collect())
@@ -293,9 +301,11 @@ fn save_settings_in(cat: &[Entry], root: &Path, meta: &Path, id: &str, changes:
let conf = active_file(root, &e)?;
let mut file = ConfFile::parse_bytes(&fs::read(&conf)?)?;
let dist = read(&dir(root).join(format!("{}.dist", conf_name(root, &e))));
let fields = if id == "playerbots" { crate::squid::fields(root)? } else { Default::default() };
let mut changed = Vec::new();
for (key, value) in changes {
let value = value.trim();
if let Some(field) = fields.get(key) { crate::squid::validate(field, value)?; }
if e.switchable && key == &e.enable_key {
return Err(Error::Invalid("Use the module switch to turn this module on or off.".into()));
}
@@ -305,6 +315,15 @@ fn save_settings_in(cat: &[Entry], root: &Path, meta: &Path, id: &str, changes:
return Err(Error::Invalid("Enemy damage must be a number from 0.25 to 2.0.".into()));
}
}
if id == "content-scaling" && key == "CoAContentScaling.World.Leech.Percent" {
let percent = value.parse::<f32>().map_err(|_| Error::Invalid("Life steal must be a number from 0 to 100 percent.".into()))?;
if !percent.is_finite() || !(0.0..=100.0).contains(&percent) {
return Err(Error::Invalid("Life steal must be a number from 0 to 100 percent.".into()));
}
}
if id == "content-scaling" && matches!(key.as_str(), "CoAContentScaling.LFG.AllowPartialGroups" | "CoAContentScaling.World.Leech.Enable") && !matches!(value, "0" | "1") {
return Err(Error::Invalid(format!("{key} must be 0 or 1.")));
}
if id == "ah-bot" && key.starts_with("AuctionHouseBot.ListProportion.Category") && key.contains(".Quality") {
let weight = value.parse::<u32>().map_err(|_| Error::Invalid("Auction listing weights must be whole numbers from 0 to 1000.".into()))?;
if weight > 1000 {
@@ -365,6 +384,27 @@ mod tests {
(root, meta)
}
#[test]
fn squid_missing_keys_use_code_defaults_and_saves_enforce_json_ranges() {
let d = tempfile::tempdir().unwrap();
let root = d.path();
fs::create_dir_all(dir(root)).unwrap();
fs::write(dir(root).join("playerbots.conf"), "AiPlayerbot.Enabled = 0\n").unwrap();
fs::write(dir(root).join("playerbots.conf.dist"), "AiPlayerbot.Enabled = 0\nAiPlayerbot.MinRandomBots = 500\n").unwrap();
fs::write(dir(root).join("playerbots.conf.settings.json"), r#"{"format":1,"groups":{"population":"Population"},"settings":[{"key":"AiPlayerbot.MinRandomBots","type":"int","group":"population","title":"Minimum bots","description":"Lower bound","default":500,"default_if_missing":50,"min":0,"max":5000}]}"#).unwrap();
let cat = catalog();
let options = settings_in(&cat, root, "playerbots").unwrap();
let option = options.iter().find(|setting| setting.key == "AiPlayerbot.MinRandomBots").unwrap();
assert_eq!(option.value, "50");
assert_eq!(option.default.as_deref(), Some("500"));
assert_eq!(option.field.as_ref().unwrap().group_title.as_deref(), Some("Population"));
let before = fs::read(dir(root).join("playerbots.conf")).unwrap();
assert!(save_settings_in(&cat, root, root, "playerbots", &BTreeMap::from([("AiPlayerbot.MinRandomBots".into(), "5001".into())])).is_err());
assert_eq!(fs::read(dir(root).join("playerbots.conf")).unwrap(), before);
save_settings_in(&cat, root, root, "playerbots", &BTreeMap::from([("AiPlayerbot.MinRandomBots".into(), "42".into())])).unwrap();
assert_eq!(settings_in(&cat, root, "playerbots").unwrap().iter().find(|setting| setting.key == "AiPlayerbot.MinRandomBots").unwrap().value, "42");
}
#[test]
fn bot_systems_are_mutually_exclusive_in_both_directions_and_manual_configs() {
let d = tempfile::tempdir().unwrap();
@@ -447,7 +487,7 @@ mod tests {
let (root, meta) = server(d.path());
let s = settings_in(&test_catalog(), &root, "war-games").unwrap();
assert_eq!(s.len(), 2);
assert_eq!(s[1], Setting { key: "WarGames.ChallengeSeconds".into(), value: "60".into(), default: Some("60".into()), doc: "How long a challenge stays open.".into() });
assert_eq!(s[1], Setting { key: "WarGames.ChallengeSeconds".into(), value: "60".into(), default: Some("60".into()), doc: "How long a challenge stays open.".into(), field: None });
assert_eq!(s[0].doc, "Turns War Games on. Second line.");
let ok = BTreeMap::from([("WarGames.ChallengeSeconds".to_string(), "90".to_string())]);
@@ -527,6 +567,39 @@ mod tests {
assert_eq!(settings_in(&cat, &root, "ah-bot").unwrap().iter().find(|s| s.key == key).unwrap().value, "0");
}
#[test]
fn partial_lfg_and_world_leech_settings_round_trip_and_reject_invalid_values() {
let d = tempfile::tempdir().unwrap();
let (root, meta) = server(d.path());
let cat = catalog();
let conf = dir(&root).join("mod-coa-content-scaling.conf.dist");
let partial = "CoAContentScaling.LFG.AllowPartialGroups";
let enable = "CoAContentScaling.World.Leech.Enable";
let percent = "CoAContentScaling.World.Leech.Percent";
let change = |k: &str, v: &str| BTreeMap::from([(k.into(), v.into())]);
fs::write(&conf, "CoAContentScaling.Enable = 1\n").unwrap();
for key in [partial, enable, percent] {
assert!(save_settings_in(&cat, &root, &meta, "content-scaling", &change(key, "1")).is_err());
}
fs::write(&conf, format!("CoAContentScaling.Enable = 1\n{partial} = 1\n{enable} = 0\n{percent} = 5.0\n")).unwrap();
for bad in ["NaN", "inf", "-0.1", "100.1", "abc"] {
assert!(save_settings_in(&cat, &root, &meta, "content-scaling", &change(percent, bad)).is_err());
}
for key in [partial, enable] {
for bad in ["2", "-1", "true", "abc"] {
assert!(save_settings_in(&cat, &root, &meta, "content-scaling", &change(key, bad)).is_err());
}
for good in ["0", "1"] {
save_settings_in(&cat, &root, &meta, "content-scaling", &change(key, good)).unwrap();
}
}
for good in ["0", "10.5", "100"] {
save_settings_in(&cat, &root, &meta, "content-scaling", &change(percent, good)).unwrap();
let settings = settings_in(&cat, &root, "content-scaling").unwrap();
assert_eq!(settings.iter().find(|s| s.key == percent).unwrap().value, good);
}
}
#[test]
fn damage_difficulty_is_validated_and_older_server_builds_do_not_accept_it() {
let d = tempfile::tempdir().unwrap();
+16 -2
View File
@@ -41,7 +41,7 @@ pub fn excluded(rel: &str) -> bool {
|| l == "mysql/my.ini"
|| l == "mysql/mysql.pid"
|| l == "mysql/data.7z"
|| l.starts_with("core/configs/") && !l.ends_with(".dist") // generated at first start from Settings templates
|| l.starts_with("core/configs/") && !l.ends_with(".dist") && l != "core/configs/modules/playerbots.conf.settings.json" // generated at first start from Settings templates
|| name.ends_with(".pdb")
|| name.ends_with(".bak")
|| name.ends_with(".log")
@@ -56,7 +56,7 @@ fn policy_for(rel: &str) -> (Owner, ReplacePolicy) {
let l = rel.to_lowercase();
if l.starts_with("_migrations/") {
(Owner::Core, ReplacePolicy::NeverTouch) // staged for the migration runner, never copied into the server
} else if l.ends_with(".dist") {
} else if l.ends_with(".dist") || l == "core/configs/modules/playerbots.conf.settings.json" {
(Owner::Core, ReplacePolicy::Replace)
} else if l.starts_with("mysql/data/") {
(Owner::User, ReplacePolicy::NeverTouch)
@@ -370,6 +370,20 @@ mod tests {
v
}
#[test]
fn upstream_settings_metadata_ships_and_updates_but_active_configs_stay_private() {
let d = tempfile::tempdir().unwrap();
let src = d.path().join("src");
fs::create_dir_all(src.join("Core/configs/modules")).unwrap();
fs::write(src.join("Core/configs/modules/playerbots.conf.settings.json"), "{}\n").unwrap();
fs::write(src.join("Core/configs/modules/playerbots.conf"), "PlayerbotsDatabaseInfo = private\n").unwrap();
let out = d.path().join("package");
let manifest = build(&src, &out, &BuildOptions { kind: Kind::Update, version: "1.0.0".into(), core_commit: None, built_at: "test".into(), part_size: 1 << 20, bots_commit: None, migrations: vec![] }, &|_| {}).unwrap();
assert_eq!(manifest.files.len(), 1);
assert_eq!(manifest.files[0].path, "Core/configs/modules/playerbots.conf.settings.json");
assert_eq!(manifest.files[0].policy, ReplacePolicy::Replace);
}
fn source() -> (tempfile::TempDir, PathBuf) {
let d = tempfile::tempdir().unwrap();
let src = d.path().join("src");
+20 -10
View File
@@ -287,25 +287,35 @@ pub fn prepare_launcher(root: &Path) -> Result<()> {
Ok(())
}
const LAUNCHER_REALM_REPLACEMENTS: &[(&str, &str)] = &[
("(\"WorldDatabaseInfo\", \"acore_world\")", "(\"WorldDatabaseInfo\", \"acore_world_wildcard\" if coa_realm() == 'wildcard' else \"acore_world\")"),
("(\"CharacterDatabaseInfo\", \"acore_characters\")", "(\"CharacterDatabaseInfo\", \"acore_characters_wildcard\" if coa_realm() == 'wildcard' else \"acore_characters\")"),
("SET name='AzerothCore',address=", "SET name='{coa_realm_name()}',address="),
("WHERE id=1;", "WHERE id={coa_realm_id()};"),
("mysql(\"UPDATE acore_auth.realmlist SET flag=0", "mysql(f\"UPDATE acore_auth.realmlist SET flag=0"),
];
const LAUNCHER_REALM_INSERT: &str = "# coa-manager-realm-profiles-v1\ndef coa_realm():\n path = ROOT / 'Settings/realm-profile.json'\n return json.loads(path.read_text(encoding='utf-8')).get('active', 'coa') if path.exists() else 'coa'\n\ndef coa_realm_id():\n return 2 if coa_realm() == 'wildcard' else 1\n\ndef coa_realm_name():\n return 'Wildcard' if coa_realm() == 'wildcard' else 'Conquest of Azeroth'\n\n";
pub(crate) fn patch_launcher(source: &str) -> Result<String> {
if source.contains("# coa-manager-realm-profiles-v1") { return Ok(source.into()); }
let replacements = [
("(\"WorldDatabaseInfo\", \"acore_world\")", "(\"WorldDatabaseInfo\", \"acore_world_wildcard\" if coa_realm() == 'wildcard' else \"acore_world\")"),
("(\"CharacterDatabaseInfo\", \"acore_characters\")", "(\"CharacterDatabaseInfo\", \"acore_characters_wildcard\" if coa_realm() == 'wildcard' else \"acore_characters\")"),
("SET name='AzerothCore',address=", "SET name='{coa_realm_name()}',address="),
("WHERE id=1;", "WHERE id={coa_realm_id()};"),
("mysql(\"UPDATE acore_auth.realmlist SET flag=0", "mysql(f\"UPDATE acore_auth.realmlist SET flag=0"),
];
let mut out = source.to_string();
for (from, to) in replacements {
for &(from, to) in LAUNCHER_REALM_REPLACEMENTS {
if !out.contains(from) { return Err(Error::Invalid("This launcher does not support realm profiles. Update the server package first.".into())); }
out = out.replace(from, to);
}
let insert = "# coa-manager-realm-profiles-v1\ndef coa_realm():\n path = ROOT / 'Settings/realm-profile.json'\n return json.loads(path.read_text(encoding='utf-8')).get('active', 'coa') if path.exists() else 'coa'\n\ndef coa_realm_id():\n return 2 if coa_realm() == 'wildcard' else 1\n\ndef coa_realm_name():\n return 'Wildcard' if coa_realm() == 'wildcard' else 'Conquest of Azeroth'\n\n";
// Insert before the entry point so ROOT, json and functions are all defined when called.
let marker = "if __name__ == \"__main__\":";
if !out.contains(marker) { return Err(Error::Invalid("Unrecognised server launcher entry point.".into())); }
Ok(out.replace(marker, &format!("{insert}{marker}")))
Ok(out.replace(marker, &format!("{LAUNCHER_REALM_INSERT}{marker}")))
}
/// Reverse only our exact realm transformation; callers must verify the recovered original hash.
pub(crate) fn unpatch_launcher(source: &str) -> Option<String> {
if !source.contains(LAUNCHER_REALM_INSERT) { return None; }
let mut original = source.replacen(LAUNCHER_REALM_INSERT, "", 1);
for &(from, to) in LAUNCHER_REALM_REPLACEMENTS { original = original.replace(to, from); }
patch_launcher(&original).ok().filter(|patched| patched == source).map(|_| original)
}
pub fn before_start(root: &Path) -> Result<()> {
+1 -1
View File
@@ -98,7 +98,7 @@ pub fn collect_bots_sql(bots: &Path) -> Result<Vec<SqlFile>> {
}
fn to_migrations(files: &[SqlFile]) -> Vec<Migration> {
files.iter().map(|f| Migration { id: f.id.clone(), db: f.db.clone(), sha256: f.sha256.clone(), destructive: false }).collect()
files.iter().map(|f| Migration { compatible_sha256: vec![], id: f.id.clone(), db: f.db.clone(), sha256: f.sha256.clone(), destructive: false }).collect()
}
pub struct UpdateParams<'a> {
+1 -1
View File
@@ -47,7 +47,7 @@ pub fn capture_release(fixture: &Path, tree: &Path, sql: &[SqlFile]) -> Result<(
return Err(Error::Invalid("Refusing to apply release SQL to a non-fixture server.".into()));
}
let staging = tempfile::tempdir()?;
let migrations: Vec<_> = sql.iter().map(|f| Migration { db: f.db.clone(), id: f.id.clone(), sha256: f.sha256.clone(), destructive: false }).collect();
let migrations: Vec<_> = sql.iter().map(|f| Migration { compatible_sha256: vec![], db: f.db.clone(), id: f.id.clone(), sha256: f.sha256.clone(), destructive: false }).collect();
for file in sql {
let path = fsx::safe_join(staging.path(), &format!("{}/{}.sql", file.db, file.id))?;
fsx::atomic_write(&path, &std::fs::read(&file.abs)?)?;
+64
View File
@@ -0,0 +1,64 @@
//! A player's client connection, independent of any local server installation.
use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
use crate::{client, fsx, Error, Result};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Profile {
pub host: String,
pub client_path: Option<String>,
}
pub fn load(dir: &Path) -> Result<Profile> {
match std::fs::read(dir.join("connection.json")) {
Ok(bytes) => Ok(serde_json::from_slice(&bytes)?),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(Profile::default()),
Err(e) => Err(e.into()),
}
}
pub fn save(dir: &Path, profile: &Profile) -> Result<()> {
if !profile.host.is_empty() && !client::host_ok(&profile.host) {
return Err(Error::Invalid("Enter a server IP address or hostname, without a URL or port.".into()));
}
if let Some(path) = &profile.client_path {
let client = PathBuf::from(path);
if client::detect(&client, None).is_none() {
return Err(Error::Invalid("This folder does not look like a game client (it needs Data and the game executable).".into()));
}
if client::is_running(&client) {
return Err(Error::Invalid("Close the game before changing its connection.".into()));
}
if !profile.host.is_empty() { client::set_realmlist(&client, dir, &profile.host)?; }
}
fsx::atomic_write_json(&dir.join("connection.json"), profile)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn connection_needs_no_server_and_survives_restart() {
let dir = tempfile::tempdir().unwrap();
let profile = Profile { host: "192.168.1.10".into(), client_path: None };
save(dir.path(), &profile).unwrap();
assert_eq!(load(dir.path()).unwrap().host, profile.host);
assert!(!dir.path().join("install.json").exists());
}
#[test]
fn linking_client_sets_host_without_touching_other_game_settings() {
let dir = tempfile::tempdir().unwrap();
let game = dir.path().join("game");
std::fs::create_dir_all(game.join("Data/enUS")).unwrap();
std::fs::write(game.join("Wow.exe"), b"fixture").unwrap();
std::fs::write(game.join("Data/enUS/realmlist.wtf"), "set realmlist 127.0.0.1\n").unwrap();
std::fs::create_dir_all(game.join("WTF")).unwrap();
std::fs::write(game.join("WTF/Config.wtf"), "SET realmName \"My realm\"\n").unwrap();
let profile = Profile { host: "192.168.1.10".into(), client_path: Some(game.to_string_lossy().into()) };
save(dir.path(), &profile).unwrap();
assert!(std::fs::read_to_string(game.join("Data/enUS/realmlist.wtf")).unwrap().contains(&profile.host));
assert_eq!(std::fs::read_to_string(game.join("WTF/Config.wtf")).unwrap(), "SET realmName \"My realm\"\n");
assert!(save(dir.path(), &Profile { host: "bad\nset realmlist other".into(), ..profile }).is_err());
assert_eq!(load(dir.path()).unwrap().host, "192.168.1.10");
}
}
+155
View File
@@ -0,0 +1,155 @@
use std::path::Path;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, PartialEq, Eq)]
pub struct Release {
pub tag: Option<String>,
pub commit: Option<String>,
}
pub fn imported_repack(root: &Path) -> bool {
root.join("CoA-Bots/release.json").is_file()
}
pub fn release(root: &Path) -> Option<Release> {
for name in ["Extras/SquidPlayerbots/release.json", "Core/configs/modules/playerbots.conf.settings.json", "CoA-Bots/release.json"] {
let Ok(bytes) = std::fs::read(root.join(name)) else { continue; };
if bytes.len() > 1024 * 1024 { continue; }
let Ok(json) = serde_json::from_slice::<serde_json::Value>(&bytes) else { continue; };
let safe = |key: &str| json.get(key).and_then(|value| value.as_str())
.filter(|value| !value.is_empty() && value.len() <= 80 && value.chars().all(|c| c.is_ascii_alphanumeric() || "._-".contains(c))).map(str::to_owned);
let tag = safe("tag").or_else(|| safe("version"));
let revision = if name == "CoA-Bots/release.json" {
json.get("botsModuleRevision").and_then(|value| value.as_str()).and_then(|value| value.split_whitespace().next()).map(str::to_owned).or_else(|| safe("commit"))
} else if name.ends_with(".settings.json") { None } else { safe("commit") };
let commit = revision.filter(|value| value.len() >= 7 && value.len() <= 40 && value.chars().all(|c| c.is_ascii_hexdigit()));
if tag.is_some() || commit.is_some() { return Some(Release { tag, commit }); }
}
None
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct Field {
pub key: String,
#[serde(rename = "type")]
pub kind: String,
pub title: String,
pub description: String,
#[serde(default)]
pub group: String,
#[serde(default)]
pub group_title: Option<String>,
pub default: serde_json::Value,
#[serde(default)]
pub default_if_missing: Option<serde_json::Value>,
pub min: Option<f64>,
pub max: Option<f64>,
}
#[derive(Deserialize)]
struct Settings {
format: u32,
settings: Vec<serde_json::Value>,
#[serde(default)]
groups: std::collections::BTreeMap<String, String>,
}
pub fn fields(root: &Path) -> crate::Result<std::collections::BTreeMap<String, Field>> {
let path = root.join("Core/configs/modules/playerbots.conf.settings.json");
if !path.is_file() { return Ok(Default::default()); }
let Ok(bytes) = std::fs::read(path) else { return Ok(Default::default()); };
if bytes.len() > 1024 * 1024 { return Ok(Default::default()); }
let Ok(settings) = serde_json::from_slice::<Settings>(&bytes) else { return Ok(Default::default()); };
if settings.format != 1 { return Ok(Default::default()); }
let mut fields = std::collections::BTreeMap::new();
for value in settings.settings {
let Ok(mut field) = serde_json::from_value::<Field>(value) else { continue; };
field.group_title = settings.groups.get(&field.group).cloned();
if !matches!(field.kind.as_str(), "bool" | "int" | "float" | "string")
|| field.key.len() > 200 || field.key.is_empty()
|| !field.key.chars().all(|c| c.is_ascii_alphanumeric() || "._".contains(c))
|| field.min.zip(field.max).is_some_and(|(min,max)| min > max)
|| !default_type(&field.kind, &field.default)
|| field.default_if_missing.as_ref().is_some_and(|value| !default_type(&field.kind, value))
|| fields.contains_key(&field.key) { continue; }
fields.insert(field.key.clone(), field);
}
Ok(fields)
}
fn default_type(kind: &str, value: &serde_json::Value) -> bool {
match kind {
"bool" => value.is_boolean(),
"int" => value.is_i64() || value.is_u64(),
"float" => value.is_number(),
"string" => value.is_string(),
_ => false,
}
}
pub fn scalar(value: &serde_json::Value) -> Option<String> {
match value {
serde_json::Value::Bool(value) => Some(if *value { "1" } else { "0" }.into()),
serde_json::Value::String(value) => Some(value.clone()),
serde_json::Value::Number(value) => Some(value.to_string()),
_ => None,
}
}
pub fn validate(field: &Field, value: &str) -> crate::Result<()> {
let valid = match field.kind.as_str() {
"bool" => matches!(value, "0" | "1"),
"int" | "float" => value.parse::<f64>().is_ok_and(|number| number.is_finite()
&& (field.kind != "int" || number.fract() == 0.0)
&& field.min.is_none_or(|min| number >= min) && field.max.is_none_or(|max| number <= max)),
"string" => true,
_ => false,
};
if valid { Ok(()) } else { Err(crate::Error::Invalid(format!("{} must match its documented SquidBots type and range.", field.key))) }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn upstream_settings_preserve_types_ranges_and_distinct_defaults() {
let root = tempfile::tempdir().unwrap();
crate::fsx::atomic_write(&root.path().join("Core/configs/modules/playerbots.conf.settings.json"), br#"{"format":1,"settings":[{"key":"AiPlayerbot.MinRandomBots","type":"int","group":"population","title":"Minimum bots","description":"Lower bound","default":500,"default_if_missing":50,"min":0,"max":5000}]}"#).unwrap();
let fields = fields(root.path()).unwrap();
let field = &fields["AiPlayerbot.MinRandomBots"];
assert_eq!(scalar(&field.default).as_deref(), Some("500"));
assert_eq!(scalar(field.default_if_missing.as_ref().unwrap()).as_deref(), Some("50"));
assert!(validate(field, "5000").is_ok());
for value in ["5001", "-1", "0.5", "NaN"] { assert!(validate(field, value).is_err()); }
}
#[test]
fn unsupported_metadata_falls_back_and_bad_entries_do_not_hide_valid_fields() {
let root = tempfile::tempdir().unwrap();
let path = root.path().join("Core/configs/modules/playerbots.conf.settings.json");
for data in [r#"{"format":99,"settings":[]}"#, "invalid json", r#"{"format":1,"settings":{}}"#] {
crate::fsx::atomic_write(&path, data.as_bytes()).unwrap();
assert!(fields(root.path()).unwrap().is_empty());
}
crate::fsx::atomic_write(&path, br#"{"format":1,"settings":[{"key":"Broken","type":"enum","title":"Broken","description":"Unknown type","default":1},{"key":"Malformed"},{"key":"WrongDefault","type":"int","title":"Wrong","description":"Bad default","default":"oops"},{"key":"Good","type":"bool","title":"Good","description":"Good field","default":true}]}"#).unwrap();
let parsed = fields(root.path()).unwrap();
assert_eq!(parsed.len(), 1);
assert!(parsed.contains_key("Good"));
}
#[test]
fn imported_revision_uses_its_first_word_and_empty_tags_are_hidden() {
let root = tempfile::tempdir().unwrap();
crate::fsx::atomic_write(&root.path().join("CoA-Bots/release.json"), br#"{"tag":"","botsModuleRevision":"48c4786a 2026-10-01 (coa branch)","commit":"abcdef01"}"#).unwrap();
assert_eq!(release(root.path()).unwrap(), Release { tag: None, commit: Some("48c4786a".into()) });
crate::fsx::atomic_write(&root.path().join("Core/configs/modules/playerbots.conf.settings.json"), br#"{"tag":"v1.8.1","commit":"11111111"}"#).unwrap();
assert_eq!(release(root.path()).unwrap(), Release { tag: Some("v1.8.1".into()), commit: None });
}
#[test]
fn diagnostics_only_expose_release_identifiers() {
let root = tempfile::tempdir().unwrap();
crate::fsx::atomic_write(&root.path().join("CoA-Bots/release.json"), br#"{"tag":"v1.8","commit":"48c4786a","password":"secret"}"#).unwrap();
assert!(imported_repack(root.path()));
assert_eq!(release(root.path()).unwrap(), Release { tag: Some("v1.8".into()), commit: Some("48c4786a".into()) });
}
}
+486 -50
View File
@@ -77,6 +77,8 @@ pub struct Txn {
pub databases_started: bool,
pub ops: Vec<Op>,
pub message: Option<String>,
#[serde(default)]
pub recovery_hashes: BTreeMap<String, String>,
}
fn legacy_databases_started() -> bool { true }
@@ -84,6 +86,8 @@ fn legacy_databases_started() -> bool { true }
/// Everything the transaction needs from the outside world; tests provide a fake.
pub trait Env {
fn ensure_stopped(&self) -> Result<()>;
fn preflight(&self, _manifest: &Manifest) -> Result<()> { Ok(()) }
fn verify_snapshot(&self, _id: &str) -> Result<()> { Ok(()) }
/// Create a recovery point for the databases and configuration; returns its id.
fn snapshot(&self) -> Result<String>;
fn restore_snapshot(&self, id: &str) -> Result<()>;
@@ -108,32 +112,72 @@ fn save(meta: &Path, t: &Txn) -> Result<()> {
}
pub fn load(meta: &Path, id: &str) -> Result<Txn> {
fsx::read_json(&txn_dir(meta, id)?.join("txn.json"))
read_journal(&txn_dir(meta, id)?.join("txn.json"))
}
fn read_journal(path: &Path) -> Result<Txn> {
let txn: Txn = fsx::read_json(path).map_err(|e| Error::Invalid(format!("Update journal {} cannot be read: {e}. Available recovery copies were preserved.", path.display())))?;
if path.parent().and_then(Path::file_name).and_then(|id| id.to_str()) != Some(txn.id.as_str()) { return Err(Error::Invalid("Update journal identity is inconsistent.".into())); }
txn_dir(path.parent().unwrap(), &txn.id)?;
if let Some(id) = &txn.recovery_point {
if id.is_empty() || !id.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | '.')) || id.contains("..") { return Err(Error::Invalid("Update journal contains an invalid recovery point identity.".into())); }
}
let valid_hash = |hash: &str| hash.len() == 64 && hash.bytes().all(|b| b.is_ascii_hexdigit());
let mut seen = std::collections::BTreeSet::new();
for op in &txn.ops {
fsx::safe_join(path.parent().unwrap(), &op.path)?;
if !seen.insert(op.path.replace('\\', "/").to_ascii_lowercase()) || !valid_hash(&op.new_sha256)
|| (op.done && !op.started && !matches!(op.action, Action::Skip | Action::Conflict))
|| (txn.state == State::Prepared && op.started)
|| (txn.state == State::Committed && !op.done) {
return Err(Error::Invalid("Update journal contains inconsistent file operations.".into()));
}
}
if txn.recovery_hashes.values().any(|hash| !valid_hash(hash)) { return Err(Error::Invalid("Update journal contains invalid recovery hashes.".into())); }
for key in txn.recovery_hashes.keys().filter(|key| !matches!(key.as_str(), "@install" | "@point")) { fsx::safe_join(path.parent().unwrap(), key)?; }
Ok(txn)
}
#[derive(Serialize, Deserialize)]
struct CleanupMarker { id: String, state: State }
fn cleanup_marker(meta: &Path, id: &str) -> Result<PathBuf> {
txn_dir(meta, id)?;
Ok(meta.join("update-cleanup").join(format!("{id}.json")))
}
fn journals(meta: &Path) -> Result<Vec<Txn>> {
let entries = match fs::read_dir(updates_dir(meta)) { Ok(entries) => entries, Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(vec![]), Err(e) => return Err(e.into()) };
let mut all = Vec::new();
for entry in entries {
let entry = entry?;
if entry.file_type()?.is_symlink() { return Err(Error::Invalid("Linked update storage cannot be recovered safely.".into())); }
if !entry.file_type()?.is_dir() { continue; }
let dir = fsx::ensure_within(meta, &entry.path())?;
let path = dir.join("txn.json");
if !path.is_file() {
let id = entry.file_name().to_string_lossy().into_owned();
let marker = cleanup_marker(meta, &id)?;
if fsx::read_json::<CleanupMarker>(&marker).is_ok_and(|m| m.id == id && matches!(m.state, State::Committed | State::RolledBack)) { continue; }
return Err(Error::Invalid(format!("Update {id} has no journal. Preserve its recovery copies and inspect it before starting or changing the server.")));
}
all.push(read_journal(&path)?);
}
all.sort_by(|a, b| b.id.cmp(&a.id));
Ok(all)
}
pub fn pending_checked(meta: &Path) -> Result<Option<Txn>> {
Ok(journals(meta)?.into_iter().find(|t| !matches!(t.state, State::Committed | State::RolledBack | State::Prepared) && (t.state != State::Failed || t.databases_started || t.ops.iter().any(|o| o.started))))
}
/// A transaction that started but never reached a final state (crash, power loss). The UI offers rollback.
pub fn unfinished(meta: &Path) -> Option<Txn> {
let rd = fs::read_dir(updates_dir(meta)).ok()?;
let mut all: Vec<Txn> = rd.flatten().filter_map(|e| fsx::read_json::<Txn>(&e.path().join("txn.json")).ok()).collect();
all.sort_by(|a, b| b.id.cmp(&a.id));
all.into_iter().find(|t| !matches!(t.state, State::Committed | State::RolledBack | State::Prepared) && (t.state != State::Failed || t.databases_started || t.ops.iter().any(|o| o.started)))
pending_checked(meta).ok().flatten()
}
pub fn ensure_recovered(meta: &Path) -> Result<()> {
match fs::read_dir(updates_dir(meta)) {
Ok(entries) => {
for entry in entries {
let entry = entry?;
let journal = entry.path().join("txn.json");
if journal.exists() {
fsx::read_json::<Txn>(&journal).map_err(|e| Error::Invalid(format!("Update journal {} cannot be read: {e}. Recover it before changing or starting the server.", journal.display())))?;
}
}
}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
Err(e) => return Err(e.into()),
}
if let Some(t) = unfinished(meta) {
if let Some(t) = pending_checked(meta)? {
return Err(Error::Invalid(format!("Resolve unfinished update {} before changing or starting the server.", t.id)));
}
Ok(())
@@ -172,8 +216,23 @@ pub fn plan(root: &Path, meta: &InstallMeta, manifest: &Manifest, resolutions: &
if would_add { (Action::MergeConfig, Some("new settings are added; your values are kept".into())) } else { (Action::Skip, Some("no new settings".into())) }
}
(_, Some(c)) if c.eq_ignore_ascii_case(&f.sha256) => (Action::Skip, Some("already up to date".into())),
(_, Some(_)) if f.path == "Scripts/manage.py" && staged.is_some_and(|tree| {
match (fs::read_to_string(tree.join(&f.path)), fs::read(&target)) {
(Ok(signed), Ok(actual)) => fsx::sha256_bytes(signed.as_bytes()) == f.sha256 && crate::driver::launcher_matches(&signed, &actual),
_ => false,
}
}) => (Action::Skip, Some("already up to date with Manager integration".into())),
(ReplacePolicy::Replace | ReplacePolicy::ReplaceIfPristine, Some(c)) => {
if recorded.map(|r| r.eq_ignore_ascii_case(c)).unwrap_or(false) {
let manager_launcher = f.path == "Scripts/manage.py" && recorded.is_some_and(|hash| {
fs::read(&target).is_ok_and(|bytes| crate::driver::launcher_matches_recorded(hash, &bytes))
});
if f.path == "Core/worldserver.exe" && meta.kind == crate::registry::InstallKind::Imported && crate::squid::imported_repack(root) {
match resolutions.get(&f.path) {
Some(Resolution::Replace) => (Action::Replace, Some("Replacing this binary stops the original SquidBots launcher/updater from accepting its hash.".into())),
Some(Resolution::Keep) => (Action::Skip, Some("kept the original SquidBots binary".into())),
None => (Action::Conflict, Some("This SquidBots repack verifies its worldserver hash. Replacing it stops Start_All_Bots/coa_update from working. Choose explicitly whether to replace this binary.".into())),
}
} else if recorded.map(|r| r.eq_ignore_ascii_case(c)).unwrap_or(false) || manager_launcher {
(Action::Replace, None)
} else if f.policy == ReplacePolicy::ReplaceIfPristine {
(Action::Skip, Some("modified outside CoA Server Manager; kept".into()))
@@ -198,24 +257,72 @@ pub struct Preview {
pub items: Vec<PlanItem>,
pub conflicts: Vec<String>,
pub migrations: usize,
pub pending_migrations: usize,
pub download_bytes: u64,
}
/// Check the signed manifest and describe the update without downloading the payload.
/// Describe the update; a managed launcher may need a one-time authenticated payload check.
pub fn preview(root: &Path, meta: &InstallMeta, source: &Source, trusted_key: &str, resolutions: &BTreeMap<String, Resolution>) -> Result<Preview> {
let meta_dir = crate::registry::metadata_dir_for(root)?;
let _lock = operation_lock(&meta_dir)?;
ensure_recovered(&meta_dir)?;
let (m, _) = fetch_manifest(source, trusted_key)?;
check_manifest(&m)?;
let items = plan(root, meta, &m, resolutions, None)?;
reject_downgrade(meta, &m)?;
let mut items = plan(root, meta, &m, resolutions, None)?;
if items.iter().any(|item| item.path == "Scripts/manage.py" && item.action != Action::Skip)
&& launcher_already_integrated(root, &meta_dir, meta, &m, source)? {
if let Some(item) = items.iter_mut().find(|item| item.path == "Scripts/manage.py") {
item.action = Action::Skip;
item.reason = Some("already up to date with Manager integration".into());
}
}
let pending_migrations = (RepackEnv { root, meta_dir: &meta_dir }).pending_migrations(&m)?;
Ok(Preview {
from_version: meta.core.version.clone(),
to_version: m.version.clone(),
conflicts: items.iter().filter(|i| i.action == Action::Conflict).map(|i| i.path.clone()).collect(),
items,
migrations: m.migrations.len(),
pending_migrations,
download_bytes: m.archive.as_ref().map(|a| a.parts.iter().map(|p| p.size).sum()).unwrap_or(0),
})
}
fn launcher_already_integrated(root: &Path, meta_dir: &Path, meta: &InstallMeta, manifest: &Manifest, source: &Source) -> Result<bool> {
let Some(file) = manifest.files.iter().find(|file| file.path == "Scripts/manage.py") else { return Ok(false); };
let actual = sha_if_exists(&root.join(&file.path));
if actual.as_ref() != meta.original_hashes.get(&file.path) || actual.is_none() { return Ok(false); }
let cache = meta_dir.join("manifests").join(format!("launcher-{}.py", file.sha256));
let signed = match fs::read(&cache) {
Ok(bytes) if fsx::sha256_bytes(&bytes) == file.sha256 => bytes,
_ => {
let temp = tempfile::tempdir()?;
let parts = fetch_parts(source, manifest, &temp.path().join("download"), &Cancel::default(), &|_, _| {})?;
package::extract(&parts, manifest, &temp.path().join("tree"), &|_, _| {})?;
let bytes = fs::read(temp.path().join("tree").join(&file.path))?;
if fsx::sha256_bytes(&bytes) != file.sha256 { return Err(Error::Invalid("The signed launcher failed verification.".into())); }
// This derived cache is optional; failure to save it does not change the server.
let _ = fsx::atomic_write(&cache, &bytes);
bytes
}
};
Ok(std::str::from_utf8(&signed).ok().is_some_and(|signed| {
fs::read(root.join(&file.path)).ok().is_some_and(|actual| crate::driver::launcher_matches(signed, &actual))
}))
}
fn reject_downgrade(meta: &InstallMeta, manifest: &Manifest) -> Result<()> {
if let Some(installed) = meta.core.version.as_deref() {
if let (Some(have), Some(candidate)) = (crate::manifest::parse_version(installed), crate::manifest::parse_version(&manifest.version)) {
if candidate < have {
return Err(Error::Invalid(format!("Installed server {installed} is newer than package {}. Use its recovery point to undo an update; older packages cannot be applied.", manifest.version)));
}
}
}
Ok(())
}
fn check_manifest(m: &Manifest) -> Result<()> {
if m.kind != Kind::Update {
return Err(Error::Invalid("This is not an update package.".into()));
@@ -259,17 +366,24 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result<Outcome> {
let _ = md;
step(report, "Checking the update", 2);
let (m, _) = fetch_manifest(&p.source, p.trusted_key)?;
let (m, manifest_bytes) = fetch_manifest(&p.source, p.trusted_key)?;
tracing::info!(root = %root.display(), from_version = ?meta.core.version, to_version = %m.version, migrations = m.migrations.len(), "server update selected");
check_manifest(&m)?;
reject_downgrade(&meta, &m)?;
p.env.preflight(&m)?;
let archive = m.archive.clone().ok_or_else(|| Error::InvalidManifest("no archive".into()))?;
let id = format!("{}-{}-{}", chrono::Utc::now().format("%Y%m%d-%H%M%S"), m.version.replace('.', "_"), uuid::Uuid::new_v4().simple());
let tdir = txn_dir(meta_dir, &id)?;
let (tree, before) = (tdir.join("tree"), tdir.join("before"));
fs::create_dir_all(&before)?;
let signature = crate::pkgsource::fetch_small(&p.source, "manifest.json.sig")?;
crate::signing::verify(&manifest_bytes, &String::from_utf8_lossy(&signature), p.trusted_key)?;
fsx::atomic_write(&tdir.join("manifest.json"), &manifest_bytes)?;
fsx::atomic_write(&tdir.join("manifest.json.sig"), &signature)?;
fsx::atomic_write(&before.join("manager-install.json"), &fs::read(meta_dir.join("install.json"))?)?;
let mut txn = Txn { id: id.clone(), state: State::Prepared, from_version: meta.core.version.clone(), to_version: m.version.clone(), recovery_point: None, databases_started: false, ops: Vec::new(), message: None };
let mut txn = Txn { id: id.clone(), state: State::Prepared, from_version: meta.core.version.clone(), to_version: m.version.clone(), recovery_point: None, databases_started: false, ops: Vec::new(), message: None, recovery_hashes: BTreeMap::new() };
txn.recovery_hashes.insert("@install".into(), fsx::sha256_file(&before.join("manager-install.json"))?);
save(meta_dir, &txn)?;
// Nothing has touched the installation yet; failures up to here just discard the staging area.
@@ -278,6 +392,7 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result<Outcome> {
let parts = fetch_parts(&p.source, &m, &meta_dir.join("staging").join("download"), &p.cancel, &|f, _| step(report, "Downloading the update", 5 + (f * 35.0) as u8))?;
step(report, "Verifying the update", 42);
package::extract(&parts, &m, &tree, &|_, _| {})?;
crate::migrations::verify_files(&m.migrations, &tree.join("_migrations"))?;
Ok(tree.clone())
})();
let tree = match staged {
@@ -307,6 +422,8 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result<Outcome> {
p.env.ensure_stopped()?;
step(report, "Saving a recovery point", 52);
txn.recovery_point = Some(p.env.snapshot().map_err(|e| Error::Invalid(format!("The update was not applied because the safety backup failed: {e}")))?);
let point_meta = meta_dir.join("backups").join(txn.recovery_point.as_deref().unwrap()).join("backup.json");
if point_meta.is_file() { txn.recovery_hashes.insert("@point".into(), fsx::sha256_file(&point_meta)?); }
txn.ops = items
.iter()
@@ -352,37 +469,80 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result<Outcome> {
return Ok(Outcome { txn, migrations: migrated });
}
// Commit
step(report, "Finishing", 96);
finish(root, meta_dir, &mut meta, &m, &tree, &mut txn)?;
step(report, "Done", 100);
let _ = archive;
Ok(Outcome { txn, migrations: migrated })
}
fn finish(root: &Path, meta_dir: &Path, meta: &mut InstallMeta, m: &Manifest, tree: &Path, txn: &mut Txn) -> Result<()> {
meta.core.version = Some(m.version.clone());
meta.core.commit = m.core.commit.clone().or(meta.core.commit);
meta.core.commit = m.core.commit.clone().or(meta.core.commit.clone());
for op in &txn.ops {
let hash = if op.path == "Scripts/manage.py" {
let staged = fs::read_to_string(tree.join(&op.path)).ok().and_then(|s| crate::realms::patch_launcher(&s).ok());
match (staged, fs::read(root.join(&op.path))) {
(Some(expected), Ok(actual)) if expected.as_bytes() == actual => fsx::sha256_bytes(&actual),
match (fs::read_to_string(tree.join(&op.path)), fs::read(root.join(&op.path))) {
(Ok(signed), Ok(actual)) if crate::driver::launcher_matches(&signed, &actual) => fsx::sha256_bytes(&actual),
_ => op.new_sha256.clone(),
}
} else { op.new_sha256.clone() };
meta.original_hashes.insert(op.path.clone(), hash);
if !meta.managed_files.contains(&op.path) {
meta.managed_files.push(op.path.clone());
if !meta.managed_files.contains(&op.path) { meta.managed_files.push(op.path.clone()); }
}
for file in &m.files {
if !txn.ops.iter().any(|op| op.path == file.path) {
let path = fsx::safe_join(root, &file.path)?;
if path.is_file() && fsx::sha256_file(&path)? == file.sha256 {
meta.original_hashes.insert(file.path.clone(), file.sha256.clone());
}
}
}
for i in items.iter().filter(|i| i.action == Action::Skip && i.reason.as_deref() == Some("already up to date")) {
if let Some(f) = m.files.iter().find(|f| f.path == i.path) {
meta.original_hashes.insert(f.path.clone(), f.sha256.clone());
}
}
fsx::atomic_write_json(&meta_dir.join("install.json"), &meta)?;
fsx::atomic_write(&meta_dir.join("manifests").join(format!("update-{}.json", m.version)), &serde_json::to_vec_pretty(&m)?)?;
fsx::atomic_write_json(&meta_dir.join("install.json"), meta)?;
fsx::atomic_write(&meta_dir.join("manifests").join(format!("update-{}.json", m.version)), &serde_json::to_vec_pretty(m)?)?;
txn.state = State::Committed;
save(meta_dir, &txn)?;
let _ = fs::remove_dir_all(&tree);
txn.message = None;
save(meta_dir, txn)?;
let _ = fs::remove_dir_all(tree);
prune(meta_dir, 3);
step(report, "Done", 100);
let _ = archive;
Ok(Outcome { txn, migrations: migrated })
Ok(())
}
pub fn retry_validation(root: &Path, meta_dir: &Path, id: &str, fallback: &Source, trusted_key: &str, env: &dyn Env) -> Result<Txn> {
let _lock = operation_lock(meta_dir)?;
let mut txn = load(meta_dir, id)?;
if txn.state != State::NeedsDecision || unfinished(meta_dir).is_none_or(|t| t.id != id) {
return Err(Error::Invalid("Only an applied update awaiting startup validation can be retried.".into()));
}
let dir = txn_dir(meta_dir, id)?;
let source = if dir.join("manifest.json").is_file() { Source::Dir(dir.clone()) } else { fallback.clone() };
let (manifest, _) = fetch_manifest(&source, trusted_key)?;
check_manifest(&manifest)?;
if manifest.version != txn.to_version || txn.ops.iter().any(|op| !op.done) {
return Err(Error::Invalid("The saved update does not match the applied transaction.".into()));
}
for op in txn.ops.iter().filter(|op| matches!(op.action, Action::Create | Action::Replace)) {
let path = fsx::safe_join(root, &op.path)?;
let file = manifest.files.iter().find(|f| f.path == op.path)
.ok_or_else(|| Error::Invalid("The update journal contains a file absent from the signed package.".into()))?;
if matches!(file.policy, ReplacePolicy::CreateIfMissing | ReplacePolicy::MergeConfig | ReplacePolicy::NeverTouch) { continue; }
let bytes = fs::read(&path)?;
let actual = fsx::sha256_bytes(&bytes);
let launcher = op.path == "Scripts/manage.py"
&& fs::read_to_string(dir.join("tree").join(&op.path)).ok()
.filter(|s| fsx::sha256_bytes(s.as_bytes()) == file.sha256)
.is_some_and(|s| crate::driver::launcher_matches(&s, &bytes));
if actual != file.sha256 && !launcher {
return Err(Error::Invalid(format!("{} changed since the update was applied; use repair or rollback.", op.path)));
}
}
env.ensure_stopped()?;
if let Err(error) = env.validate() {
txn.message = Some(format!("The updated server did not start correctly: {error}"));
save(meta_dir, &txn)?;
return Ok(txn);
}
let (_, mut meta) = MetaDir::open(meta_dir)?;
finish(root, meta_dir, &mut meta, &manifest, &dir.join("tree"), &mut txn)?;
Ok(txn)
}
fn fail_after_apply(p: &Params, txn: &mut Txn, before: &Path, tree: &Path, why: String, report: Option<ApplyReport>) -> Result<Outcome> {
@@ -402,6 +562,19 @@ fn fail_after_apply(p: &Params, txn: &mut Txn, before: &Path, tree: &Path, why:
}
fn restore_transaction(root: &Path, meta: &Path, before: &Path, txn: &mut Txn, env: &dyn Env) -> Result<()> {
for (rel, expected) in &txn.recovery_hashes {
let saved = match rel.as_str() {
"@install" => before.join("manager-install.json"),
"@point" => meta.join("backups").join(txn.recovery_point.as_deref().ok_or_else(|| Error::Invalid("The recovery point identity is missing.".into()))?).join("backup.json"),
_ => fsx::safe_join(before, rel)?,
};
if fsx::sha256_file(&saved)? != *expected { return Err(Error::Invalid(format!("Recovery copy {rel} is damaged; no restoration was started."))); }
}
if let Some(id) = &txn.recovery_point { env.verify_snapshot(id)?; }
for op in txn.ops.iter().filter(|op| op.started && op.had_previous) {
if !fsx::safe_join(before, &op.path)?.is_file() { return Err(Error::Invalid(format!("The recovery copy of {} is missing; no restoration was started.", op.path))); }
}
if !before.join("manager-install.json").is_file() { return Err(Error::Invalid("The saved installation metadata is missing; no restoration was started.".into())); }
env.ensure_stopped()?;
if txn.databases_started {
let id = txn.recovery_point.as_deref().ok_or_else(|| Error::Invalid("The database recovery point is missing.".into()))?;
@@ -429,6 +602,7 @@ fn apply_ops(root: &Path, tree: &Path, before: &Path, files: &[FileEntry], txn:
let keep = fsx::safe_join(before, &path)?;
fs::create_dir_all(keep.parent().unwrap())?;
fsx::atomic_write(&keep, &fs::read(&target)?)?;
txn.recovery_hashes.insert(path.clone(), fsx::sha256_file(&keep)?);
}
// Journal only after the old bytes are safely saved; a crash during backup must not
// turn an untouched file into a rollback operation with a missing saved copy.
@@ -519,7 +693,10 @@ pub(crate) fn begin_repair(root: &Path, meta_dir: &Path, version: &str, backup:
if had_previous { fsx::atomic_write(&fsx::safe_join(&before, &file.path)?, &fs::read(&target)?)?; }
ops.push(Op { path: file.path.clone(), action: if had_previous { Action::Replace } else { Action::Create }, reason: None, new_sha256: file.sha256.clone(), had_previous, started: true, done: false });
}
let txn = Txn { id, state: State::Applying, from_version: Some(version.into()), to_version: version.into(), recovery_point: Some(backup.into()), databases_started: false, ops, message: Some("Repair is in progress.".into()) };
let mut recovery_hashes = BTreeMap::new();
recovery_hashes.insert("@install".into(), fsx::sha256_file(&before.join("manager-install.json"))?);
for op in ops.iter().filter(|op| op.had_previous) { recovery_hashes.insert(op.path.clone(), fsx::sha256_file(&fsx::safe_join(&before, &op.path)?)?); }
let txn = Txn { id, state: State::Applying, from_version: Some(version.into()), to_version: version.into(), recovery_point: Some(backup.into()), databases_started: false, ops, message: Some("Repair is in progress.".into()), recovery_hashes };
save(meta_dir, &txn)?;
Ok(txn)
}
@@ -538,10 +715,15 @@ pub(crate) fn finish_repair(root: &Path, meta_dir: &Path, txn: &mut Txn, success
fn prune(meta_dir: &Path, keep: usize) {
let Ok(rd) = fs::read_dir(updates_dir(meta_dir)) else { return };
let mut dirs: Vec<_> = rd.flatten().filter(|e| fsx::read_json::<Txn>(&e.path().join("txn.json")).is_ok_and(|t| matches!(t.state, State::Committed | State::RolledBack))).map(|e| e.path()).collect();
let mut dirs: Vec<_> = rd.flatten().filter(|e| read_journal(&e.path().join("txn.json")).is_ok_and(|t| matches!(t.state, State::Committed | State::RolledBack))).map(|e| e.path()).collect();
dirs.sort();
while dirs.len() > keep {
let _ = fs::remove_dir_all(dirs.remove(0));
let dir = dirs.remove(0);
if let Ok(txn) = read_journal(&dir.join("txn.json")) {
if let Ok(marker) = cleanup_marker(meta_dir, &txn.id) {
if fsx::atomic_write_json(&marker, &CleanupMarker { id: txn.id, state: txn.state }).is_ok() && fs::remove_dir_all(&dir).is_ok() { let _ = fs::remove_file(marker); }
}
}
}
}
@@ -552,6 +734,20 @@ pub struct RepackEnv<'a> {
}
impl RepackEnv<'_> {
pub fn pending_migrations(&self, manifest: &Manifest) -> Result<usize> {
if manifest.migrations.is_empty() { return Ok(0); }
crate::backup::with_database(self.root, |db| {
let realms = crate::realms::state(self.root)?;
let mut modes = vec![realms.active];
if realms.wildcard_created { modes.push(if realms.active == crate::realms::Mode::Coa { crate::realms::Mode::Wildcard } else { crate::realms::Mode::Coa }); }
let mut count = 0;
for (index, mode) in modes.into_iter().enumerate() {
let list: Vec<_> = manifest.migrations.iter().filter(|m| index == 0 || m.db != "auth").cloned().collect();
count += crate::migrations::pending_count(&db.clone().for_realm(mode), &list)?;
}
Ok(count)
})
}
pub(crate) fn verify_recovery_point(&self, point: &crate::backup::RecoveryPoint) -> Result<()> {
if point.kind != crate::backup::Kind::Full || !["characters", "auth", "world", "configs"].iter().all(|name| point.components.iter().any(|c| c.name == *name)) {
return Err(Error::Invalid("The update recovery point does not contain every required database and configuration.".into()));
@@ -581,6 +777,18 @@ impl RepackEnv<'_> {
}
impl Env for RepackEnv<'_> {
fn preflight(&self, manifest: &Manifest) -> Result<()> {
self.pending_migrations(manifest).map(|_| ())
}
fn verify_snapshot(&self, id: &str) -> Result<()> {
let point = crate::backup::get(self.meta_dir, id)?;
if point.kind != crate::backup::Kind::Full || !["characters", "auth", "world", "configs"].iter().all(|name| point.components.iter().any(|c| c.name == *name)) {
return Err(Error::Invalid("The recovery point is incomplete; no restoration was started.".into()));
}
if !crate::backup::verify(self.meta_dir, id)?.ok { return Err(Error::Invalid("The recovery point is damaged; available copies were preserved.".into())); }
Ok(())
}
fn ensure_stopped(&self) -> Result<()> {
use crate::process::{observe, ServiceState};
let o = observe(self.root, &crate::layout::read_ports(self.root));
@@ -696,7 +904,7 @@ impl Env for RepackEnv<'_> {
if healthy {
return Ok(());
}
let cause = started.human.map(|h| h.title.to_string()).or_else(|| crate::health::diagnose_installation(self.root).map(|c| c.human().title.to_string())).unwrap_or_else(|| "the server did not become ready".into());
let cause = crate::driver::startup_failure(self.root, &started);
// Leave the files unlocked so that a rollback can replace them.
let _ = crate::driver::run(self.root, crate::driver::Verb::StopAll);
Err(Error::Invalid(cause))
@@ -718,16 +926,20 @@ mod tests {
snapshot_ok: Cell<bool>,
calls: RefCell<Vec<&'static str>>,
migrate_fail: Cell<bool>,
preflight_fail: Cell<bool>,
restore_fail: Cell<bool>,
}
impl Fake {
fn ok() -> Fake {
Fake { stopped: Cell::new(true), healthy: Cell::new(true), snapshot_ok: Cell::new(true), calls: Default::default(), migrate_fail: Cell::new(false), restore_fail: Cell::new(false) }
Fake { stopped: Cell::new(true), healthy: Cell::new(true), snapshot_ok: Cell::new(true), calls: Default::default(), migrate_fail: Cell::new(false), preflight_fail: Cell::new(false), restore_fail: Cell::new(false) }
}
}
impl Env for Fake {
fn preflight(&self, _: &Manifest) -> Result<()> {
if self.preflight_fail.get() { Err(Error::Invalid("Conflicting migration history".into())) } else { Ok(()) }
}
fn ensure_stopped(&self) -> Result<()> {
self.calls.borrow_mut().push("stop");
if self.stopped.get() { Ok(()) } else { Err(Error::Invalid("The server is running.".into())) }
@@ -798,7 +1010,7 @@ mod tests {
let mut m = build(&src, &pkg, &BuildOptions { kind: Kind::Update, version: "2.0.0".into(), core_commit: None, built_at: "x".into(), part_size: 1 << 20, bots_commit: None, migrations: vec![] }, &|_| {}).unwrap();
// Settings/* are merge-config by the packager; make the migration entry visible to the runner
if migrations {
m.migrations.push(crate::manifest::Migration { id: "m1".into(), db: "world".into(), sha256: fsx::sha256_bytes(b"SELECT 1;"), destructive: false });
m.migrations.push(crate::manifest::Migration { compatible_sha256: vec![], id: "m1".into(), db: "world".into(), sha256: fsx::sha256_bytes(b"SELECT 1;"), destructive: false });
fs::write(pkg.join("manifest.json"), serde_json::to_vec_pretty(&m).unwrap()).unwrap();
}
let sk = SigningKey::generate(&mut rand_core::OsRng);
@@ -807,6 +1019,52 @@ mod tests {
World { _d: d, root, meta: meta_dir, pkg, key: base64::engine::general_purpose::STANDARD.encode(sk.verifying_key().to_bytes()) }
}
const LEGACY_LAUNCHER: &str = "import sys\nROOT = Path(__file__).resolve().parents[1]\nfrom squid_playerbots import validate_bots\n(\"WorldDatabaseInfo\", \"acore_world\")\n(\"CharacterDatabaseInfo\", \"acore_characters\")\nSET name='AzerothCore',address=\nWHERE id=1;\nmysql(\"UPDATE acore_auth.realmlist SET flag=0\nif __name__ == \"__main__\":\n";
fn legacy_launcher_world(import_patch: bool) -> World {
let w = world(&[("Scripts/manage.py", b"new release launcher")], false);
let mut source = crate::realms::patch_launcher(LEGACY_LAUNCHER).unwrap();
if import_patch { source = crate::driver::patch_launcher_imports(&source).unwrap(); }
write(&w.root, "Scripts/manage.py", source.as_bytes());
let (_, mut meta) = MetaDir::open(&w.meta).unwrap();
// Older Managers retained the signed original hash after adding realm profiles.
meta.original_hashes.insert("Scripts/manage.py".into(), fsx::sha256_bytes(LEGACY_LAUNCHER.as_bytes()));
fsx::atomic_write_json(&w.meta.join("install.json"), &meta).unwrap();
w
}
#[test]
fn legacy_manager_realm_launcher_is_replaced_during_update() {
let w = legacy_launcher_world(false);
let outcome = run(&w, &Fake::ok(), BTreeMap::new(), None).unwrap();
assert_eq!(outcome.txn.state, State::Committed);
assert_eq!(read(&w, "Scripts/manage.py"), b"new release launcher");
}
#[test]
fn legacy_realm_and_import_repairs_are_replaced_during_update() {
let w = legacy_launcher_world(true);
let outcome = run(&w, &Fake::ok(), BTreeMap::new(), None).unwrap();
assert_eq!(outcome.txn.state, State::Committed);
assert_eq!(read(&w, "Scripts/manage.py"), b"new release launcher");
}
#[test]
fn genuine_launcher_edits_still_require_a_decision_and_can_be_kept() {
let w = legacy_launcher_world(true);
let mut custom = read(&w, "Scripts/manage.py");
custom.extend_from_slice(b"\n# owner's custom integration\n");
write(&w.root, "Scripts/manage.py", &custom);
let (_, meta) = MetaDir::open(&w.meta).unwrap();
let manifest = Manifest::parse(&fs::read(w.pkg.join("manifest.json")).unwrap()).unwrap();
let items = plan(&w.root, &meta, &manifest, &BTreeMap::new(), None).unwrap();
assert_eq!(items.iter().find(|item| item.path == "Scripts/manage.py").unwrap().action, Action::Conflict);
let resolutions = BTreeMap::from([("Scripts/manage.py".into(), Resolution::Keep)]);
let outcome = run(&w, &Fake::ok(), resolutions, None).unwrap();
assert_eq!(outcome.txn.state, State::Committed);
assert_eq!(read(&w, "Scripts/manage.py"), custom);
}
fn run(w: &World, env: &Fake, res: BTreeMap<String, Resolution>, fail_after: Option<usize>) -> Result<Outcome> {
apply(
&Params { root: &w.root, meta_dir: &w.meta, source: Source::Dir(w.pkg.clone()), trusted_key: &w.key, cancel: Cancel::default(), resolutions: res, env, fail_after_ops: fail_after },
@@ -818,6 +1076,22 @@ mod tests {
fs::read(w.root.join(rel)).unwrap()
}
#[test]
fn imported_squid_repack_requires_a_decision_even_for_pristine_worldserver() {
let w = world(&[], false);
write(&w.root, "CoA-Bots/release.json", b"{}");
let (_, mut meta) = MetaDir::open(&w.meta).unwrap();
meta.kind = InstallKind::Imported;
let manifest: Manifest = serde_json::from_slice(&fs::read(w.pkg.join("manifest.json")).unwrap()).unwrap();
let action = |resolutions: BTreeMap<String, Resolution>| {
plan(&w.root, &meta, &manifest, &resolutions, None).unwrap().into_iter().find(|item| item.path == "Core/worldserver.exe").unwrap().action
};
assert_eq!(action(BTreeMap::new()), Action::Conflict);
assert_eq!(action(BTreeMap::from([("Core/worldserver.exe".into(), Resolution::Keep)])), Action::Skip);
assert_eq!(action(BTreeMap::from([("Core/worldserver.exe".into(), Resolution::Replace)])), Action::Replace);
assert_eq!(read(&w, "Core/worldserver.exe"), b"world-v1");
}
#[test]
fn happy_path_replaces_creates_merges_and_records_ownership() {
let w = world(&[], false);
@@ -838,6 +1112,47 @@ mod tests {
assert!(!w.root.join("Core/worldserver.exe.coa-new").exists());
}
#[test]
fn an_integrated_launcher_is_current_but_user_edits_and_new_package_bytes_are_not() {
let source = b"import sys\nfrom pathlib import Path\nfrom squid_playerbots import configure\nROOT = Path(__file__).resolve().parents[1]\n";
let w = world(&[("Scripts/manage.py", source)], false);
run(&w, &Fake::ok(), BTreeMap::new(), None).unwrap();
let integrated = crate::driver::patch_launcher_imports(std::str::from_utf8(source).unwrap()).unwrap();
write(&w.root, "Scripts/manage.py", integrated.as_bytes());
let (_, mut meta) = MetaDir::open(&w.meta).unwrap();
meta.original_hashes.insert("Scripts/manage.py".into(), fsx::sha256_bytes(integrated.as_bytes()));
fsx::atomic_write_json(&w.meta.join("install.json"), &meta).unwrap();
let p = preview(&w.root, &meta, &Source::Dir(w.pkg.clone()), &w.key, &BTreeMap::new()).unwrap();
assert_eq!(p.items.iter().find(|item| item.path == "Scripts/manage.py").unwrap().action, Action::Skip);
let manifest = fetch_manifest(&Source::Dir(w.pkg.clone()), &w.key).unwrap().0;
let applied_plan = plan(&w.root, &meta, &manifest, &BTreeMap::new(), Some(&w._d.path().join("upd"))).unwrap();
assert_eq!(applied_plan.iter().find(|item| item.path == "Scripts/manage.py").unwrap().action, Action::Skip);
let mut changed = fetch_manifest(&Source::Dir(w.pkg.clone()), &w.key).unwrap().0;
changed.files.iter_mut().find(|file| file.path == "Scripts/manage.py").unwrap().sha256 = fsx::sha256_bytes(b"new launcher");
assert!(launcher_already_integrated(&w.root, &w.meta, &meta, &changed, &Source::Dir(w.pkg.clone())).is_err());
write(&w.root, "Scripts/manage.py", format!("{integrated}\n# user edit\n").as_bytes());
let p = preview(&w.root, &meta, &Source::Dir(w.pkg.clone()), &w.key, &BTreeMap::new()).unwrap();
assert_eq!(p.items.iter().find(|item| item.path == "Scripts/manage.py").unwrap().action, Action::Conflict);
meta.original_hashes.insert("Scripts/manage.py".into(), fsx::sha256_file(&w.root.join("Scripts/manage.py")).unwrap());
let p = preview(&w.root, &meta, &Source::Dir(w.pkg.clone()), &w.key, &BTreeMap::new()).unwrap();
assert_eq!(p.items.iter().find(|item| item.path == "Scripts/manage.py").unwrap().action, Action::Replace,
"Recorded user content must not be mistaken for a recognized Manager integration");
}
#[test]
fn older_packages_are_rejected_before_preview_or_application() {
let w = world(&[], false);
let (_, mut installed) = MetaDir::open(&w.meta).unwrap();
installed.core.version = Some("3.0.0".into());
fsx::atomic_write_json(&w.meta.join("install.json"), &installed).unwrap();
let env = Fake::ok();
assert!(run(&w, &env, BTreeMap::new(), None).unwrap_err().to_string().contains("newer than package"));
assert!(preview(&w.root, &installed, &Source::Dir(w.pkg.clone()), &w.key, &BTreeMap::new()).unwrap_err().to_string().contains("newer than package"));
assert!(env.calls.borrow().is_empty());
assert_eq!(read(&w, "Core/worldserver.exe"), b"world-v1");
assert!(pending_checked(&w.meta).unwrap().is_none());
}
#[test]
fn a_file_modified_by_the_user_is_a_conflict_until_resolved() {
let w = world(&[], false);
@@ -901,6 +1216,53 @@ mod tests {
assert!(rollback(&w.root, &w.meta, &out.txn.id, &env).is_err(), "already rolled back");
}
#[test]
fn retrying_startup_commits_without_reapplying_sql_or_restoring_databases() {
let w = world(&[], true);
let env = Fake::ok();
env.healthy.set(false);
let out = run(&w, &env, BTreeMap::new(), None).unwrap();
let calls = env.calls.borrow().len();
env.healthy.set(true);
let done = retry_validation(&w.root, &w.meta, &out.txn.id, &Source::Dir(w.pkg.clone()), &w.key, &env).unwrap();
assert_eq!(done.state, State::Committed);
assert_eq!(done.recovery_point, out.txn.recovery_point);
assert_eq!(&env.calls.borrow()[calls..], &["stop", "validate"]);
assert!(unfinished(&w.meta).is_none());
assert_eq!(MetaDir::open(&w.meta).unwrap().1.core.version.as_deref(), Some("2.0.0"));
}
#[test]
fn legacy_retry_uses_the_exact_signed_release_and_preserves_failure() {
let w = world(&[], false);
let env = Fake::ok();
env.healthy.set(false);
let out = run(&w, &env, BTreeMap::new(), None).unwrap();
let dir = txn_dir(&w.meta, &out.txn.id).unwrap();
fs::remove_file(dir.join("manifest.json")).unwrap();
fs::remove_file(dir.join("manifest.json.sig")).unwrap();
let pending = retry_validation(&w.root, &w.meta, &out.txn.id, &Source::Dir(w.pkg.clone()), &w.key, &env).unwrap();
assert_eq!(pending.state, State::NeedsDecision);
assert_eq!(pending.recovery_point, out.txn.recovery_point);
assert!(pending.message.unwrap().contains("worldserver exited"));
rollback(&w.root, &w.meta, &out.txn.id, &env).unwrap();
assert!(retry_validation(&w.root, &w.meta, &out.txn.id, &Source::Dir(w.pkg.clone()), &w.key, &env).is_err());
}
#[test]
fn retry_rejects_modified_binaries_and_unsigned_manifests() {
let w = world(&[], false);
let env = Fake::ok();
env.healthy.set(false);
let out = run(&w, &env, BTreeMap::new(), None).unwrap();
write(&w.root, "Core/worldserver.exe", b"unexpected binary");
assert!(retry_validation(&w.root, &w.meta, &out.txn.id, &Source::Dir(w.pkg.clone()), &w.key, &env).is_err());
write(&w.root, "Core/worldserver.exe", b"world-v2");
fs::write(txn_dir(&w.meta, &out.txn.id).unwrap().join("manifest.json.sig"), "invalid").unwrap();
assert!(retry_validation(&w.root, &w.meta, &out.txn.id, &Source::Dir(w.pkg.clone()), &w.key, &env).is_err());
assert_eq!(unfinished(&w.meta).unwrap().state, State::NeedsDecision);
}
#[test]
fn crash_recovery_uses_the_journal() {
let w = world(&[], false);
@@ -913,6 +1275,7 @@ mod tests {
t.state = State::Applying;
for op in t.ops.iter_mut() {
op.started = op.path == "Core/worldserver.exe";
op.done &= op.started;
}
save(&w.meta, &t).unwrap();
assert_eq!(unfinished(&w.meta).unwrap().id, id);
@@ -1012,6 +1375,79 @@ mod tests {
assert!(unfinished(&w.meta).is_none());
}
#[test]
fn sql_manifest_mismatch_is_rejected_before_snapshot_or_replacement() {
let w = world(&[], true);
let manifest_path = w.pkg.join("manifest.json");
let mut manifest: Manifest = fsx::read_json(&manifest_path).unwrap();
manifest.migrations[0].sha256 = "a".repeat(64);
let bytes = serde_json::to_vec_pretty(&manifest).unwrap();
// A publisher mistake: valid signed archive bytes disagree with the SQL metadata.
let key = SigningKey::generate(&mut rand_core::OsRng);
let trusted = base64::engine::general_purpose::STANDARD.encode(key.verifying_key().to_bytes());
fs::write(&manifest_path, &bytes).unwrap();
fs::write(w.pkg.join("manifest.json.sig"), base64::engine::general_purpose::STANDARD.encode(key.sign(&bytes).to_bytes())).unwrap();
let env = Fake::ok();
let error = apply(&Params { root: &w.root, meta_dir: &w.meta, source: Source::Dir(w.pkg.clone()), trusted_key: &trusted,
cancel: Default::default(), resolutions: Default::default(), env: &env, fail_after_ops: None }, &|_, _| {}).unwrap_err();
assert!(matches!(error, Error::HashMismatch { .. }), "Expected SQL metadata mismatch, received {error}");
assert!(env.calls.borrow().is_empty());
assert_eq!(read(&w, "Core/worldserver.exe"), b"world-v1");
assert!(pending_checked(&w.meta).unwrap().is_none());
}
#[test]
fn preflight_rejection_precedes_snapshot_and_file_changes() {
let w = world(&[], true);
let env = Fake::ok();
env.preflight_fail.set(true);
let original = fsx::sha256_file(&w.meta.join("install.json")).unwrap();
assert!(run(&w, &env, BTreeMap::new(), None).unwrap_err().to_string().contains("Conflicting migration history"));
assert_eq!(read(&w, "Core/worldserver.exe"), b"world-v1");
assert_eq!(fsx::sha256_file(&w.meta.join("install.json")).unwrap(), original);
assert!(env.calls.borrow().is_empty());
assert!(fs::read_dir(w.meta.join("updates")).unwrap().next().is_none());
}
#[test]
fn missing_and_semantically_corrupt_journals_block_operations() {
let w = world(&[], false);
let txn = run(&w, &Fake::ok(), BTreeMap::new(), None).unwrap().txn;
let path = txn_dir(&w.meta, &txn.id).unwrap().join("txn.json");
let mut bad = txn.clone();
bad.id = "another-update".into();
fsx::atomic_write_json(&path, &bad).unwrap();
assert!(pending_checked(&w.meta).is_err());
bad = txn.clone();
bad.ops[0].path = "../outside".into();
fsx::atomic_write_json(&path, &bad).unwrap();
assert!(ensure_recovered(&w.meta).is_err());
bad = txn.clone();
bad.ops[0].started = false;
fsx::atomic_write_json(&path, &bad).unwrap();
assert!(ensure_recovered(&w.meta).is_err());
fs::remove_file(&path).unwrap();
assert!(pending_checked(&w.meta).is_err());
let marker = cleanup_marker(&w.meta, &txn.id).unwrap();
fsx::atomic_write_json(&marker, &CleanupMarker { id: txn.id, state: State::Committed }).unwrap();
assert!(pending_checked(&w.meta).unwrap().is_none());
}
#[test]
fn damaged_saved_file_blocks_restore_before_any_environment_action() {
let w = world(&[], false);
let env = Fake::ok();
env.healthy.set(false);
let txn = run(&w, &env, BTreeMap::new(), None).unwrap().txn;
let before = txn_dir(&w.meta, &txn.id).unwrap().join("before");
write(&before, "Core/worldserver.exe", b"damaged original");
env.calls.borrow_mut().clear();
assert!(rollback(&w.root, &w.meta, &txn.id, &env).unwrap_err().to_string().contains("damaged"));
assert!(env.calls.borrow().is_empty());
assert_eq!(read(&w, "Core/worldserver.exe"), b"world-v2");
assert_eq!(pending_checked(&w.meta).unwrap().unwrap().state, State::NeedsDecision);
}
#[test]
fn unreadable_update_journal_blocks_changes_and_startup() {
let w = world(&[], false);
+6 -1
View File
@@ -578,6 +578,11 @@ The reference install classifies as **Healthy (customised)**: repack shape, bina
* **UI:** PLAY becomes **UPDATE CLIENT** when a tracked client is outdated (with "Play without updating"); with no client linked it
becomes **Set up game client** (choose an existing folder, or download into `<chosen folder>/CoA Client` with a free-space check).
An existing client that is not tracked can be adopted from Settings > Game client ("Keep this client up to date").
A fresh download gets `realmlist.wtf` for each installed locale (the manifest has none) and the companion addon.
A fresh download gets `realmlist.wtf` for each installed locale (the manifest has none) and, for local hosts, the companion addon.
* **Joining another server:** the welcome screen offers hosting or joining. Joining uses a separate player profile in
the Manager's `remote-client/connection.json`, storing the host address and client folder without a server registry entry,
installation metadata, database or server processes. Only Overview and application Settings appear in the sidebar.
Downloading, adopting and updating clients use the same verified downloader; Play applies the saved realmlist without
forcing a local realm selection. The player can return to hosting without removing their saved connection.
* **Open points:** ask the launcher maintainers before putting heavy load on their API; DBCs live inside the MPQ patch archives
(extracting them would need an MPQ reader), so the server's `Data\dbc` still comes from our `base` package for now.
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "coa-server-manager",
"version": "0.6.2",
"version": "0.6.5",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "coa-server-manager",
"version": "0.6.2",
"version": "0.6.5",
"dependencies": {
"@tauri-apps/api": "^2.12.0",
"@tauri-apps/plugin-dialog": "^2.8.0",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "coa-server-manager",
"private": true,
"version": "0.6.2",
"version": "0.6.5",
"license": "AGPL-3.0-only",
"type": "module",
"scripts": {
+114 -32
View File
@@ -697,7 +697,7 @@ async fn check_update(state: State<'_, AppState>, id: String, source: Option<Str
#[tauri::command]
fn pending_update(state: State<'_, AppState>, id: String) -> std::result::Result<Option<update::Txn>, UiError> {
let root = path_of(&state, &id)?;
Ok(update::unfinished(&meta_dir(&root)?))
Ok(update::pending_checked(&meta_dir(&root)?)?)
}
#[tauri::command]
@@ -744,6 +744,19 @@ async fn rollback_update(state: State<'_, AppState>, id: String, txn: String) ->
.await
}
#[tauri::command]
async fn retry_update_validation(state: State<'_, AppState>, id: String, txn: String) -> std::result::Result<update::Txn, UiError> {
let root = path_of(&state, &id)?;
let _guard = BusyGuard::acquire(&state, &id)?;
blocking(move || {
let dir = meta_dir(&root)?;
let pending = update::load(&dir, &txn)?;
let source = coa_core::pkgsource::Source::Url(format!("https://github.com/Corfirean/coa-server-build/releases/download/server-{}/", pending.to_version));
let env = update::RepackEnv { root: &root, meta_dir: &dir };
update::retry_validation(&root, &dir, &txn, &source, coa_core::signing::EMBEDDED_PUBLIC_KEY, &env)
}).await
}
#[tauri::command]
async fn get_population(state: State<'_, AppState>, id: String) -> std::result::Result<Option<coa_core::population::Population>, UiError> {
let root = path_of(&state, &id)?;
@@ -929,6 +942,68 @@ async fn add_companions(state: State<'_, AppState>, id: String, count: u32) -> s
.await
}
const REMOTE_CLIENT_ID: &str = "@remote-client";
fn remote_dir() -> PathBuf { data_dir().join("remote-client") }
#[tauri::command]
fn remote_connection() -> std::result::Result<coa_core::remote_client::Profile, UiError> {
Ok(coa_core::remote_client::load(&remote_dir())?)
}
#[tauri::command]
fn remote_connect(state: State<'_, AppState>, host: String) -> std::result::Result<coa_core::remote_client::Profile, UiError> {
let job = state.client_cancel.lock().unwrap();
if job.is_some() { return Err(Error::Invalid("Wait for the client operation to finish.".into()).into()); }
let dir = remote_dir();
let mut profile = coa_core::remote_client::load(&dir)?;
let host = host.trim();
if host.is_empty() { return Err(Error::Invalid("Enter the host's IP address or hostname.".into()).into()); }
profile.host = host.into();
coa_core::remote_client::save(&dir, &profile)?;
Ok(profile)
}
struct ClientContext {
dir: PathBuf,
path: Option<PathBuf>,
source: Option<PathBuf>,
host: String,
root: Option<PathBuf>,
}
fn client_context(state: &AppState, id: &str) -> Result<ClientContext> {
if id == REMOTE_CLIENT_ID {
let dir = remote_dir();
let profile = coa_core::remote_client::load(&dir)?;
return Ok(ClientContext { dir, path: profile.client_path.map(PathBuf::from), source: None, host: profile.host, root: None });
}
let root = path_of(state, id)?;
let (dir, meta) = install_meta(&root)?;
let source = coa_core::client::addon_source(&root);
Ok(ClientContext { dir, path: meta.client_path.map(PathBuf::from), source, host: "127.0.0.1".into(), root: Some(root) })
}
impl ClientContext {
fn linked(&self) -> Option<PathBuf> {
self.path.clone().filter(|p| coa_core::client::detect(p, None).is_some())
}
fn require(&self) -> Result<PathBuf> {
self.linked().ok_or_else(|| Error::Invalid("Set up a game client first.".into()))
}
fn link(&self, path: &str) -> Result<()> {
if let Some(root) = &self.root {
let (_, mut meta) = install_meta(root)?;
meta.client_path = Some(path.into());
coa_core::fsx::atomic_write_json(&self.dir.join("install.json"), &meta)
} else {
let mut profile = coa_core::remote_client::load(&self.dir)?;
profile.client_path = Some(path.into());
coa_core::remote_client::save(&self.dir, &profile)
}
}
}
fn client_of(root: &std::path::Path) -> Result<(PathBuf, InstallMeta, Option<PathBuf>)> {
let (dir, meta) = install_meta(root)?;
let client = meta.client_path.clone().map(PathBuf::from).ok_or_else(|| Error::Invalid("No game client is set up for this server yet.".into()))?;
@@ -937,22 +1012,19 @@ fn client_of(root: &std::path::Path) -> Result<(PathBuf, InstallMeta, Option<Pat
#[tauri::command]
fn client_info(state: State<'_, AppState>, id: String) -> std::result::Result<Option<coa_core::client::ClientInfo>, UiError> {
let root = path_of(&state, &id)?;
let (_, meta) = install_meta(&root)?;
let source = coa_core::client::addon_source(&root);
Ok(meta.client_path.and_then(|p| coa_core::client::detect(std::path::Path::new(&p), source.as_deref())))
let ctx = client_context(&state, &id)?;
Ok(ctx.path.and_then(|p| coa_core::client::detect(&p, ctx.source.as_deref())))
}
#[tauri::command]
fn set_client(state: State<'_, AppState>, id: String, path: String) -> std::result::Result<coa_core::client::ClientInfo, UiError> {
let root = path_of(&state, &id)?;
let (dir, mut meta) = install_meta(&root)?;
let source = coa_core::client::addon_source(&root);
let info = coa_core::client::detect(std::path::Path::new(&path), source.as_deref())
let job = state.client_cancel.lock().unwrap();
if job.is_some() { return Err(Error::Invalid("Wait for the client operation to finish.".into()).into()); }
let ctx = client_context(&state, &id)?;
let info = coa_core::client::detect(std::path::Path::new(&path), ctx.source.as_deref())
.ok_or_else(|| Error::Invalid("This folder does not look like a game client (it needs Data and the game executable).".into()))?;
meta.client_path = Some(info.path.clone());
coa_core::fsx::atomic_write_json(&dir.join("install.json"), &meta).map_err(UiError::from)?;
Ok(info)
ctx.link(&info.path)?;
Ok(coa_core::client::detect(std::path::Path::new(&info.path), ctx.source.as_deref()).unwrap_or(info))
}
#[tauri::command]
@@ -991,9 +1063,9 @@ fn linked_client(root: &std::path::Path) -> Result<Option<PathBuf>> {
/// Cheap: one small manifest request and the local state file; no game file is read.
#[tauri::command]
async fn client_status(state: State<'_, AppState>, id: String) -> std::result::Result<ClientStatus, UiError> {
let root = path_of(&state, &id)?;
let ctx = client_context(&state, &id)?;
blocking(move || {
let client = linked_client(&root)?;
let client = ctx.linked();
let latest = coa_core::clientdl::fetch_latest().ok();
let local = client.as_deref().map(coa_core::clientdl::local);
let managed = local.as_ref().map(|l| l.managed).unwrap_or(false);
@@ -1040,10 +1112,10 @@ async fn client_download_check(parent: String) -> std::result::Result<ClientDown
/// Compare the linked client with the published one. Hashes files only where the recorded state cannot vouch for them.
#[tauri::command]
async fn client_plan(app: AppHandle, state: State<'_, AppState>, id: String) -> std::result::Result<coa_core::clientdl::Plan, UiError> {
let root = path_of(&state, &id)?;
let ctx = client_context(&state, &id)?;
let cancel = begin_client_job(&state)?;
let result = blocking(move || {
let client = linked_client(&root)?.ok_or_else(|| Error::Invalid("No game client is set up for this server yet.".into()))?;
let client = ctx.require()?;
let manifest = coa_core::clientdl::fetch_latest()?;
let current = coa_core::clientdl::load_state(&client).unwrap_or_default();
coa_core::clientdl::plan(&client, &manifest, &current, &cancel, &|s| {
@@ -1058,11 +1130,13 @@ async fn client_plan(app: AppHandle, state: State<'_, AppState>, id: String) ->
/// Bring the linked client to the published version. `keep_modified` leaves files the player changed alone.
#[tauri::command]
async fn client_sync(app: AppHandle, state: State<'_, AppState>, id: String, keep_modified: bool) -> std::result::Result<(), UiError> {
let root = path_of(&state, &id)?;
let ctx = client_context(&state, &id)?;
let cancel = begin_client_job(&state)?;
let result = blocking(move || {
let client = linked_client(&root)?.ok_or_else(|| Error::Invalid("No game client is set up for this server yet.".into()))?;
run_client_sync(&app, &client, keep_modified, &cancel)
let client = ctx.require()?;
run_client_sync(&app, &client, keep_modified, &cancel)?;
if ctx.root.is_none() && !ctx.host.is_empty() { coa_core::client::set_realmlist(&client, &ctx.dir, &ctx.host)?; }
Ok(())
})
.await;
end_client_job(&state);
@@ -1086,13 +1160,12 @@ fn run_client_sync(app: &AppHandle, client: &std::path::Path, keep_modified: boo
Ok(())
}
/// Download the whole client into `<parent>/CoA Client`, then link it to this server.
/// Download the client into `<parent>/CoA Client`, then link it to a host or player profile.
#[tauri::command]
async fn client_download(app: AppHandle, state: State<'_, AppState>, id: String, parent: String) -> std::result::Result<coa_core::client::ClientInfo, UiError> {
let root = path_of(&state, &id)?;
let ctx = client_context(&state, &id)?;
let cancel = begin_client_job(&state)?;
let result = blocking(move || {
let (dir, mut meta) = install_meta(&root)?;
let parent = PathBuf::from(&parent);
if !parent.is_dir() {
return Err(Error::Invalid("Choose an existing folder to put the game client in.".into()));
@@ -1105,16 +1178,11 @@ async fn client_download(app: AppHandle, state: State<'_, AppState>, id: String,
}
std::fs::create_dir_all(&dest)?;
run_client_sync(&app, &dest, false, &cancel)?;
let source = coa_core::client::addon_source(&root);
let info = coa_core::client::detect(&dest, source.as_deref()).ok_or_else(|| Error::Invalid("The downloaded client looks incomplete.".into()))?;
meta.client_path = Some(info.path.clone());
coa_core::fsx::atomic_write_json(&dir.join("install.json"), &meta)?;
// a fresh client has no realmlist; this server is on this computer
coa_core::client::set_realmlist(&dest, &dir, "127.0.0.1")?;
if let Some(src) = source {
coa_core::client::install_addon(&dest, &dir, &src)?;
}
Ok(coa_core::client::detect(&dest, coa_core::client::addon_source(&root).as_deref()).unwrap_or(info))
let info = coa_core::client::detect(&dest, ctx.source.as_deref()).ok_or_else(|| Error::Invalid("The downloaded client looks incomplete.".into()))?;
ctx.link(&info.path)?;
if !ctx.host.is_empty() { coa_core::client::set_realmlist(&dest, &ctx.dir, &ctx.host)?; }
if let Some(src) = &ctx.source { coa_core::client::install_addon(&dest, &ctx.dir, src)?; }
Ok(coa_core::client::detect(&dest, ctx.source.as_deref()).unwrap_or(info))
})
.await;
end_client_job(&state);
@@ -1149,6 +1217,17 @@ fn end_client_job(state: &AppState) {
/// Launch the game client independently of the local server.
#[tauri::command]
async fn play(state: State<'_, AppState>, id: String) -> std::result::Result<DriverOutcome, UiError> {
if id == REMOTE_CLIENT_ID {
let ctx = client_context(&state, &id)?;
let client = ctx.require()?;
return blocking(move || {
if ctx.host.is_empty() { return Err(Error::Invalid("Enter the host's IP address or hostname first.".into())); }
if coa_core::client::is_running(&client) { return Err(Error::Invalid("The game is already running.".into())); }
coa_core::client::set_realmlist(&client, &ctx.dir, &ctx.host)?;
coa_core::client::launch(&client)?;
Ok(DriverOutcome { ok: true, exit_code: None, code: None, human: None, output: String::new() })
}).await;
}
let root = path_of(&state, &id)?;
let (dir, _, client) = client_of(&root)?;
let client = client.unwrap();
@@ -1492,6 +1571,7 @@ pub fn run() {
pending_update,
apply_update,
rollback_update,
retry_update_validation,
get_population,
get_performance,
companions_stop_spawning,
@@ -1501,6 +1581,8 @@ pub fn run() {
open_link,
companion_sizes,
add_companions,
remote_connection,
remote_connect,
client_info,
set_client,
client_realmlist,
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "CoA Server Manager",
"version": "0.6.2",
"version": "0.6.5",
"identifier": "com.coa.servermanager",
"build": {
"beforeDevCommand": "npm run dev",
+17 -2
View File
@@ -4,14 +4,20 @@ import { Welcome } from "@/screens/Welcome";
import { ImportServer } from "@/screens/ImportServer";
import { Shell } from "@/screens/Shell";
import { InstallServer } from "@/screens/InstallServer";
import { RemoteClient } from "@/screens/RemoteClient";
import { UpdateBanner } from "@/components/UpdateBanner";
import { autoUpdateEnabled, installOnClose, lookForUpdate } from "@/lib/selfUpdate";
type View = "welcome" | "add" | "import" | "install";
type View = "welcome" | "add" | "import" | "install" | "remote";
function initialView(): View {
try { return localStorage.getItem("coa-play-mode") === "remote" ? "remote" : "welcome"; }
catch { return "welcome"; }
}
function Main() {
const [servers, setServers] = useState<ServerSummary[] | null>(null);
const [view, setView] = useState<View>("welcome");
const [view, setView] = useState<View>(initialView);
const [activeId, setActiveId] = useState<string | null>(null);
const refresh = useCallback(async () => {
@@ -26,6 +32,11 @@ function Main() {
if (servers === null) return null;
if (view === "remote") return <RemoteClient onHost={() => {
try { localStorage.setItem("coa-play-mode", "host"); } catch { /* storage unavailable */ }
setView(servers.length ? "welcome" : "add");
}} />;
if (servers.length > 0 && view === "welcome" && activeId) {
return (
<Shell
@@ -71,6 +82,10 @@ function Main() {
return (
<Welcome
onConnect={() => {
try { localStorage.setItem("coa-play-mode", "remote"); } catch { /* storage unavailable */ }
setView("remote");
}}
onImport={() => setView("import")}
onInstall={() => setView("install")}
onBack={servers.length > 0 ? () => setView("welcome") : undefined}
+7 -3
View File
@@ -10,6 +10,7 @@ export {};
let added = new URLSearchParams(location.search).has("demo"), running = false;
let realm: "coa" | "wildcard" = "coa", wildcardCreated = false;
let simultaneous = false;
let remoteHost = localStorage.getItem("demo-remote-host") ?? "";
const moduleEdits: Record<string, Record<string, string>> = {};
const modState: Record<string, boolean> = { "companions": true, "content-scaling": true, "client-compat": true, "tbc-content": true, "wotlk-content": true, "npc-enchanter": true };
const report = {path:"C:\\games\\CoA-Repack",classification:"healthy",items:[
@@ -30,6 +31,9 @@ export {};
if(cmd==="check_database") return [{realm, migrations:[],problems:[],full_schema:false}];
if(cmd==="repair_server") { if(running) throw new Error("Stop the server before repairing it."); return {restored:[],applied:[],backup:"demo-before-repair",database:[{realm,migrations:[],problems:[],full_schema:false}],error:null}; }
if(cmd==="realm_select"){await new Promise(r=>setTimeout(r,600));realm=args.mode;wildcardCreated ||= realm==="wildcard";modState.companions=realm==="coa";return {active:realm,wildcard_created:wildcardCreated,supported:true,recovery_pending:false,simultaneous,secondary_world_port:simultaneous?8086:null,secondary_running:simultaneous&&running};}
if(cmd==="remote_connection") return {host:remoteHost,client_path:null};
if(cmd==="remote_connect") { remoteHost=args.host.trim(); localStorage.setItem("demo-remote-host",remoteHost); return {host:remoteHost,client_path:null}; }
if(cmd==="play") return {ok:true,exit_code:null,code:null,human:null,output:""};
if(cmd==="list_servers") return added?[{id:"1",name:"CoA-Repack",path:report.path}]:[];
if(cmd==="scan_server") return report;
if(cmd==="add_server"){added=true;return {id:"1",name:"CoA-Repack",path:report.path};}
@@ -42,7 +46,7 @@ export {};
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==="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.261001.8":"0.260930.5",to_version:"0.261001.8",items:[],conflicts:[],migrations:5,download_bytes:6000000};
if(cmd==="check_update") return {from_version:(window as any).__updated?"0.261001.8":"0.260930.5",to_version:"0.261001.8",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.261001.8"},migrations:null};}
if(cmd==="get_population"){if(!running) return null;let b=(window as any).__bots??85;const t=(window as any).__target??0;if(t>b){b=Math.min(t,b+25);(window as any).__bots=b;}return {online_total:b,bots_online:Math.max(0,b-7),players_online:0,bots_total:b};}
if(cmd==="get_performance") return running?{mean_ms:14,median_ms:15,p95_ms:24,p99_ms:30,max_ms:61,ticks_per_sec:71.4}:null;
@@ -75,7 +79,7 @@ export {};
"npc-enchanter":[{key:"Enchanter.Enable",value:"1",default:"1",doc:"Enable the module."},{key:"Enchanter.Announce",value:"0",default:"0",doc:"Announce the module when the player logs in."},{key:"Enchanter.CostCopper",value:"0",default:"0",doc:"What one enchantment costs, in copper (10000 = 1 gold). 0 = free."},{key:"Enchanter.MessageTimer",value:"60000",default:"60000",doc:"How often the NPC emotes, in milliseconds."}],
"playerbots":[{"key": "AiPlayerbot.RandomBotAutologin", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.MinRandomBots", "value": "500", "default": "500", "doc": ""}, {"key": "AiPlayerbot.MaxRandomBots", "value": "500", "default": "500", "doc": ""}, {"key": "AiPlayerbot.RandomBotAccountCount", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.RandomBotMinLevel", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.RandomBotMaxLevel", "value": "60", "default": "60", "doc": ""}, {"key": "AiPlayerbot.SyncLevelWithPlayers", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.RandomBotInvitePlayer", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.RandomBotJoinLfg", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.RandomBotJoinBG", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.RandomBotAutoJoinBG", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.RandomBotTalk", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.RandomBotEmote", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.RandomBotSuggestDungeons", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.CoaClassesOnly", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.CoaSmartHeal", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.CoaSmartTank", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.CoaSpecRotations", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.CoaInterruptCoordination", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.MaxAddedBots", "value": "40", "default": "40", "doc": ""}, {"key": "AiPlayerbot.BotAutologin", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.DisabledWithoutRealPlayer", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.AddClassCommand", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.KeepAltsInGroup", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.CoaRecruitSameFaction", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.CoaLfgBots", "value": "1", "default": "1", "doc": ""}, {"key": "AiPlayerbot.RandomBotXPRate", "value": "1.0", "default": "1.0", "doc": ""}, {"key": "AiPlayerbot.FollowDistance", "value": "1.5", "default": "1.5", "doc": ""}, {"key": "AiPlayerbot.Enabled", "value": "0", "default": "0", "doc": ""}, {"key": "AiPlayerbot.RandomBotAccountPrefix", "value": "\"rndbot\"", "default": "\"rndbot\"", "doc": ""}, {"key": "AiPlayerbot.RandomBotUpdateInterval", "value": "20", "default": "20", "doc": ""}],
"companions":[{key:"CoaBots.Enable",value:"1",default:"1",doc:"Master switch of the companion bots."},{key:"CoaBots.RandomSpawn.DefaultCount",value:"10",default:"10",doc:""}],
"content-scaling":[{key:"CoAContentScaling.Enable",value:"1",default:"1",doc:"Scale dungeons and raids to the group."}, ...[{key:"CoAContentScaling.Difficulty.DamageMultiplier",value:"1.0"},{key:"CoAContentScaling.SoloAssist.Mode",value:"1"},{key:"CoAContentScaling.GroupScaling.Enable",value:"1"},{key:"CoAContentScaling.LFG.DefaultMode",value:"CurrentParty"},{key:"CoAContentScaling.LFG.DefaultChallengeSize",value:"0"},{key:"CoAContentScaling.Debug",value:"0"}].map(s=>({...s,default:s.value,doc:""}))],
"content-scaling":[{key:"CoAContentScaling.Enable",value:"1",default:"1",doc:"Scale dungeons and raids to the group."}, ...[{key:"CoAContentScaling.LFG.AllowPartialGroups",value:"1"},{key:"CoAContentScaling.World.Leech.Enable",value:"0"},{key:"CoAContentScaling.World.Leech.Percent",value:"5.0"},{key:"CoAContentScaling.Difficulty.DamageMultiplier",value:"1.0"},{key:"CoAContentScaling.SoloAssist.Mode",value:"1"},{key:"CoAContentScaling.GroupScaling.Enable",value:"1"},{key:"CoAContentScaling.LFG.DefaultMode",value:"CurrentParty"},{key:"CoAContentScaling.LFG.DefaultChallengeSize",value:"0"},{key:"CoAContentScaling.Debug",value:"0"}].map(s=>({...s,default:s.value,doc:""}))],
"ah-bot":[...Object.keys(auctionCategories).flatMap(category => Object.keys(auctionQualities).map(quality => ({key:`AuctionHouseBot.ListProportion.Category${category}.Quality${quality}`,value:String(quality === "Normal" && !["Quest","Key","Generic","Reagent"].includes(category) ? 50 : quality === "Rare" && ["Armor","Weapon"].includes(category) ? 5 : 0),default:String(quality === "Normal" && !["Quest","Key","Generic","Reagent"].includes(category) ? 50 : quality === "Rare" && ["Armor","Weapon"].includes(category) ? 5 : 0),doc:""}))), {key:"AuctionHouseBot.Enable",value:"false",default:"false",doc:""}, ...[{key:"AuctionHouseBot.GUIDs",value:"0"},{key:"AuctionHouseBot.EnableSeller",value:"true"},{key:"AuctionHouseBot.CoA.ObtainableItemsOnly",value:"true"},{key:"AuctionHouseBot.ItemsPerCycle",value:"150"},{key:"AuctionHouseBot.MinutesBetweenSellCycle",value:"1"},{key:"AuctionHouseBot.Alliance.MinItems",value:"15000"},{key:"AuctionHouseBot.Alliance.MaxItems",value:"15000"}].map(s=>({...s,default:s.value,doc:""}))],
"tbc-content":[{key:"CoATBC.Enable",value:"1",default:"1",doc:"Outland dungeons and raids."}],
"wotlk-content":[{key:"CoAWotLK.Enable",value:"1",default:"1",doc:"Northrend dungeons and raids."}],
@@ -92,7 +96,7 @@ export {};
if(cmd==="account_set_access"){const a=(window as any).__acc.find((x: any)=>x.name===args.name);if(a)a.access=args.level;return null;}
if(cmd==="account_set_password") return null;
if(cmd==="account_rename"){const a=(window as any).__acc.find((x: any)=>x.name===args.name);if(a)a.name=String(args.newName).toUpperCase();return null;}
if(cmd==="client_info"){const c=(window as any).__client??"none";return c==="none"?null:{path:"C:\\games\\CoA Client",executable:"Ascension.exe",realmlists:[{path:"x",host:"127.0.0.1"}],addon:{installed:true,version:"1",up_to_date:true},other_addons:2};}
if(cmd==="client_info"){const c=(window as any).__client??"none";return c==="none"?null:{path:"C:\\games\\CoA Client",executable:"Ascension.exe",realmlists:[{path:"x",host:args.id==="@remote-client"?remoteHost:"127.0.0.1"}],addon:{installed:true,version:"1",up_to_date:true},other_addons:2};}
if(cmd==="set_client"){(window as any).__client="foreign";return {path:args.path,executable:"Ascension.exe",realmlists:[],addon:{installed:false,version:null,up_to_date:null},other_addons:0};}
if(cmd==="plugin:event|listen"){const w=window as any;(w.__handlers??={})[args.event]=[...(w.__handlers[args.event]??[]),args.handler];return 1;}
if(cmd==="plugin:event|unlisten") return null;
+19
View File
@@ -2,6 +2,21 @@ import type en from "./en";
/** Deutsch. Entwurf einer Übersetzung; vor der Veröffentlichung von Muttersprachlern zu prüfen. */
const de: Partial<Record<keyof typeof en, string>> = {
"remote.clientReady": "Dein Client ist bereit. Speichere die Hostadresse und klicke auf Spielen.",
"remote.clientIntro": "Wähle einen vorhandenen Spielclient oder lade ihn hier herunter. Ein lokaler Server ist nicht nötig.",
"welcome.host.title": "Einen Server hosten",
"welcome.host.text": "Einen neuen Server installieren oder einen vorhandenen verwalten.",
"welcome.connect.title": "Mit anderem Server verbinden",
"welcome.connect.text": "Den Spielclient herunterladen oder aktualisieren und bei Freunden spielen.",
"remote.intro": "Richte deinen Spielclient ein. Dein Freund betreibt den Server.",
"remote.address": "Serveradresse",
"remote.addressHint": "Für LAN-Spiele frage den Host nach der lokalen IP-Adresse seines Computers.",
"remote.save": "Adresse speichern",
"remote.saved": "Serveradresse gespeichert.",
"remote.accountHint": "Bitte den Host, ein Spielkonto für dich anzulegen.",
"remote.hostInstead": "Eigenen Server hosten",
"welcome.roleSubtitle": "Wie möchtest du spielen?",
"nav.overview": "Übersicht",
"nav.bots": "Bots",
"nav.server": "Server",
@@ -58,6 +73,9 @@ const de: Partial<Record<keyof typeof en, string>> = {
"btn.stop": "SERVER STOPPEN",
"btn.stopSmall": "Stoppen",
"btn.restart": "Neustart",
"btn.startWithoutUpdate": "Ohne Update starten",
"btn.playWithoutUpdate": "Ohne Update spielen",
"import.squidRepackWarning": "Dieses SquidBots-Repack prüft den Worldserver-Hash. Ein Austausch kann Start_All_Bots und coa_update deaktivieren. Updates fragen vorher nach.",
"btn.play": "SPIELEN",
"btn.startPlay": "STARTEN & SPIELEN",
"btn.startingCaps": "STARTET …",
@@ -346,6 +364,7 @@ const de: Partial<Record<keyof typeof en, string>> = {
"upd.confirmBack": "Zur vorherigen Version zurückkehren? Deine Charaktere und Konten werden nicht verändert.",
"upd.wentBack": "Zur vorherigen Version zurückgekehrt. Deine Daten wurden nicht angetastet.",
"upd.dialogTitle": "Wähle einen Update-Paketordner",
"upd.retryValidation": "Serverstart erneut prüfen",
"upd.pendingBad": "Der aktualisierte Server ist nicht korrekt gestartet",
"upd.pendingUnfinished": "Ein früheres Update wurde nicht abgeschlossen",
"upd.safeBack": "Du kannst sicher zur vorherigen Version zurückkehren.",
+19
View File
@@ -1,5 +1,20 @@
/** English is the source of truth: every key must exist here; other locales fall back to it. */
const en = {
"remote.clientReady": "Your client is ready. Save the host’s address, then press Play.",
"remote.clientIntro": "Choose an existing game client or download one here. No local server is needed.",
"welcome.host.title": "Host a server",
"welcome.host.text": "Install a new server or manage one you already have.",
"welcome.connect.title": "Connect to another server",
"welcome.connect.text": "Download or update the game client and play on a friend’s server.",
"remote.intro": "Set up your game client. Your friend runs the server.",
"remote.address": "Server address",
"remote.addressHint": "For LAN play, ask the host for their computer’s local IP address.",
"remote.save": "Save address",
"remote.saved": "Server address saved.",
"remote.accountHint": "Ask the host to create a game account for you.",
"remote.hostInstead": "Host my own server",
"welcome.roleSubtitle": "How would you like to play?",
"realm.profileLabel": "Realm",
"realm.startupTitle": "Realm startup",
"realm.secondWorld": "Second world",
@@ -89,6 +104,9 @@ const en = {
"btn.stop": "STOP SERVER",
"btn.stopSmall": "Stop",
"btn.restart": "Restart",
"btn.startWithoutUpdate": "Start without updating",
"btn.playWithoutUpdate": "Play without updating",
"import.squidRepackWarning": "This SquidBots repack checks its worldserver hash. Replacing the binary can stop Start_All_Bots and coa_update from working. Updates will ask before replacing it.",
"btn.play": "PLAY",
"btn.startPlay": "START & PLAY",
"btn.startingCaps": "STARTING…",
@@ -379,6 +397,7 @@ const en = {
"upd.confirmBack": "Go back to the previous version? Your characters and accounts are not changed.",
"upd.wentBack": "Went back to the previous version. Your data was not touched.",
"upd.dialogTitle": "Choose an update package folder",
"upd.retryValidation": "Retry server startup",
"upd.pendingBad": "The updated server did not start correctly",
"upd.pendingUnfinished": "An earlier update did not finish",
"upd.safeBack": "You can safely go back to the previous version.",
+19
View File
@@ -2,6 +2,21 @@ import type en from "./en";
/** Español. Traducción provisional; debe revisarla un hablante nativo antes de publicarse. */
const es: Partial<Record<keyof typeof en, string>> = {
"remote.clientReady": "Tu cliente está listo. Guarda la dirección del anfitrión y pulsa Jugar.",
"remote.clientIntro": "Elige un cliente existente o descárgalo aquí. No necesitas un servidor local.",
"welcome.host.title": "Alojar un servidor",
"welcome.host.text": "Instalar un servidor nuevo o gestionar uno existente.",
"welcome.connect.title": "Conectarse a otro servidor",
"welcome.connect.text": "Descargar o actualizar el cliente y jugar en el servidor de un amigo.",
"remote.intro": "Configura tu cliente. Tu amigo aloja el servidor.",
"remote.address": "Dirección del servidor",
"remote.addressHint": "Para jugar en LAN, pide al anfitrión la IP local de su ordenador.",
"remote.save": "Guardar dirección",
"remote.saved": "Dirección del servidor guardada.",
"remote.accountHint": "Pide al anfitrión que te cree una cuenta de juego.",
"remote.hostInstead": "Alojar mi servidor",
"welcome.roleSubtitle": "¿Cómo quieres jugar?",
"nav.overview": "Resumen",
"nav.bots": "Bots",
"nav.server": "Servidor",
@@ -58,6 +73,9 @@ const es: Partial<Record<keyof typeof en, string>> = {
"btn.stop": "DETENER SERVIDOR",
"btn.stopSmall": "Detener",
"btn.restart": "Reiniciar",
"btn.startWithoutUpdate": "Iniciar sin actualizar",
"btn.playWithoutUpdate": "Jugar sin actualizar",
"import.squidRepackWarning": "Este repack SquidBots verifica el hash del servidor. Sustituirlo puede impedir el funcionamiento de Start_All_Bots y coa_update. Se solicitará confirmación.",
"btn.play": "JUGAR",
"btn.startPlay": "INICIAR Y JUGAR",
"btn.startingCaps": "INICIANDO…",
@@ -346,6 +364,7 @@ const es: Partial<Record<keyof typeof en, string>> = {
"upd.confirmBack": "¿Volver a la versión anterior? Tus personajes y cuentas no se modifican.",
"upd.wentBack": "Se volvió a la versión anterior. Tus datos no se tocaron.",
"upd.dialogTitle": "Elige una carpeta de paquete de actualización",
"upd.retryValidation": "Reintentar iniciar el servidor",
"upd.pendingBad": "El servidor actualizado no se inició correctamente",
"upd.pendingUnfinished": "Una actualización anterior no terminó",
"upd.safeBack": "Puedes volver con seguridad a la versión anterior.",
+19
View File
@@ -2,6 +2,21 @@ import type en from "./en";
/** Français. Traduction provisoire ; à faire relire par un locuteur natif avant la publication. */
const fr: Partial<Record<keyof typeof en, string>> = {
"remote.clientReady": "Votre client est prêt. Enregistrez l’adresse de l’hôte, puis cliquez sur Jouer.",
"remote.clientIntro": "Choisissez un client existant ou téléchargez-le ici. Aucun serveur local n’est nécessaire.",
"welcome.host.title": "Héberger un serveur",
"welcome.host.text": "Installer un serveur ou gérer un serveur existant.",
"welcome.connect.title": "Rejoindre un autre serveur",
"welcome.connect.text": "Télécharger ou mettre à jour le client et jouer sur le serveur d’un ami.",
"remote.intro": "Configurez votre client. Votre ami héberge le serveur.",
"remote.address": "Adresse du serveur",
"remote.addressHint": "Pour jouer en réseau local, demandez l’adresse IP locale de l’ordinateur hôte.",
"remote.save": "Enregistrer l’adresse",
"remote.saved": "Adresse du serveur enregistrée.",
"remote.accountHint": "Demandez à l’hôte de créer un compte de jeu pour vous.",
"remote.hostInstead": "Héberger mon serveur",
"welcome.roleSubtitle": "Comment souhaitez-vous jouer ?",
"nav.overview": "Vue d’ensemble",
"nav.bots": "Bots",
"nav.server": "Serveur",
@@ -58,6 +73,9 @@ const fr: Partial<Record<keyof typeof en, string>> = {
"btn.stop": "ARRÊTER LE SERVEUR",
"btn.stopSmall": "Arrêter",
"btn.restart": "Redémarrer",
"btn.startWithoutUpdate": "Démarrer sans mise à jour",
"btn.playWithoutUpdate": "Jouer sans mise à jour",
"import.squidRepackWarning": "Ce repack SquidBots vérifie le hash du serveur. Le remplacer peut empêcher Start_All_Bots et coa_update de fonctionner. Une confirmation sera demandée.",
"btn.play": "JOUER",
"btn.startPlay": "DÉMARRER ET JOUER",
"btn.startingCaps": "DÉMARRAGE…",
@@ -346,6 +364,7 @@ const fr: Partial<Record<keyof typeof en, string>> = {
"upd.confirmBack": "Revenir à la version précédente ? Vos personnages et comptes ne sont pas modifiés.",
"upd.wentBack": "Retour à la version précédente effectué. Vos données n’ont pas été touchées.",
"upd.dialogTitle": "Choisissez un dossier de paquet de mise à jour",
"upd.retryValidation": "Réessayer de démarrer le serveur",
"upd.pendingBad": "Le serveur mis à jour n’a pas démarré correctement",
"upd.pendingUnfinished": "Une mise à jour précédente ne s’est pas terminée",
"upd.safeBack": "Vous pouvez revenir en toute sécurité à la version précédente.",
+19
View File
@@ -2,6 +2,21 @@ import type en from "./en";
/** Русский. Черновой перевод; требует проверки носителем перед релизом. */
const ru: Partial<Record<keyof typeof en, string>> = {
"remote.clientReady": "Клиент готов. Сохраните адрес хоста и нажмите «Играть».",
"remote.clientIntro": "Выберите существующий клиент игры или скачайте его здесь. Локальный сервер не требуется.",
"welcome.host.title": "Хочу быть хостом",
"welcome.host.text": "Установить новый сервер или управлять существующим.",
"welcome.connect.title": "Подключиться к другому серверу",
"welcome.connect.text": "Скачать или обновить клиент и играть на сервере друга.",
"remote.intro": "Настройте игровой клиент. Сервер запускает ваш друг.",
"remote.address": "Адрес сервера",
"remote.addressHint": "Для игры по локальной сети попросите у хоста локальный IP его компьютера.",
"remote.save": "Сохранить адрес",
"remote.saved": "Адрес сервера сохранён.",
"remote.accountHint": "Попросите хоста создать для вас игровой аккаунт.",
"remote.hostInstead": "Создать свой сервер",
"welcome.roleSubtitle": "Как вы хотите играть?",
"realm.profileLabel": "Реалм",
"realm.startupTitle": "Запуск реалмов",
"realm.secondWorld": "Второй мир",
@@ -89,6 +104,9 @@ const ru: Partial<Record<keyof typeof en, string>> = {
"btn.stop": "ОСТАНОВИТЬ СЕРВЕР",
"btn.stopSmall": "Остановить",
"btn.restart": "Перезапустить",
"btn.startWithoutUpdate": "Запустить без обновления",
"btn.playWithoutUpdate": "Играть без обновления",
"import.squidRepackWarning": "Этот репак SquidBots проверяет хеш worldserver. Замена файла может нарушить работу Start_All_Bots и coa_update. Перед заменой менеджер запросит ваше решение.",
"btn.play": "ИГРАТЬ",
"btn.startPlay": "ЗАПУСТИТЬ И ИГРАТЬ",
"btn.startingCaps": "ЗАПУСК…",
@@ -377,6 +395,7 @@ const ru: Partial<Record<keyof typeof en, string>> = {
"upd.confirmBack": "Вернуться к предыдущей версии? Ваши персонажи и учётные записи не изменятся.",
"upd.wentBack": "Выполнен возврат к предыдущей версии. Ваши данные не затронуты.",
"upd.dialogTitle": "Выберите папку с пакетом обновления",
"upd.retryValidation": "Повторить запуск сервера",
"upd.pendingBad": "Обновлённый сервер запустился некорректно",
"upd.pendingUnfinished": "Предыдущее обновление не завершилось",
"upd.safeBack": "Можно безопасно вернуться к предыдущей версии.",
+19
View File
@@ -1,5 +1,20 @@
/** Simplified Chinese localization (zh-CN) */
const zh = {
"remote.clientReady": "客户端已就绪。保存服主地址,然后点击开始游戏。",
"remote.clientIntro": "选择已有游戏客户端,或在此下载。无需安装本地服务器。",
"welcome.host.title": "我要搭建服务器",
"welcome.host.text": "安装新服务器或管理已有服务器。",
"welcome.connect.title": "连接其他服务器",
"welcome.connect.text": "下载或更新游戏客户端,在朋友的服务器上游玩。",
"remote.intro": "设置游戏客户端,服务器由朋友运行。",
"remote.address": "服务器地址",
"remote.addressHint": "在局域网中游玩时,请向服主询问其电脑的局域网 IP 地址。",
"remote.save": "保存地址",
"remote.saved": "服务器地址已保存。",
"remote.accountHint": "请服主为你创建游戏账号。",
"remote.hostInstead": "搭建自己的服务器",
"welcome.roleSubtitle": "你想如何游玩?",
"realm.profileLabel": "服务器",
"realm.switching": "正在切换服务器…",
"realm.create": "创建 Wildcard 服务器",
@@ -70,6 +85,9 @@ const zh = {
"btn.stop": "停止服务器",
"btn.stopSmall": "停止",
"btn.restart": "重启",
"btn.startWithoutUpdate": "不更新启动服务器",
"btn.playWithoutUpdate": "不更新开始游戏",
"import.squidRepackWarning": "此 SquidBots 整合包会检查 worldserver 哈希。替换程序可能导致 Start_All_Bots 和 coa_update 无法运行。更新前会要求您选择。",
"btn.play": "开始游戏",
"btn.startPlay": "启动并开始游戏",
"btn.startingCaps": "正在启动…",
@@ -358,6 +376,7 @@ const zh = {
"upd.confirmBack": "是否回滚至上一个版本?你的角色与账号数据不会受到影响。",
"upd.wentBack": "已回滚至上一个版本。你的个人数据完好无损。",
"upd.dialogTitle": "选择更新包文件夹",
"upd.retryValidation": "重试启动服务器",
"upd.pendingBad": "更新后的服务器未能正常启动",
"upd.pendingUnfinished": "先前的更新尚未完成",
"upd.safeBack": "你可以安全回滚至先前的稳定版本。",
+9
View File
@@ -1,5 +1,8 @@
import { invoke } from "@tauri-apps/api/core";
export const REMOTE_CLIENT_ID = "@remote-client";
export interface RemoteConnection { host: string; client_path: string | null }
export type Classification = "healthy" | "partial" | "unknown-custom" | "incompatible";
export type ItemStatus = "found" | "missing" | "attention";
@@ -190,6 +193,7 @@ export interface RealmProfile {
export interface ModuleView {
id: string;
name: string;
version?: string | null;
description: Record<string, string>;
repo: string;
/** the module is part of this server build (its configuration exists) */
@@ -213,6 +217,7 @@ export interface ModuleSetting {
value: string;
default: string | null;
doc: string;
field?: { key: string; type: string; title: string; description: string; group: string; group_title?: string | null; min?: number | null; max?: number | null } | null;
}
export interface AllSetting {
@@ -265,6 +270,7 @@ export interface UpdatePreview {
items: UpdatePlanItem[];
conflicts: string[];
migrations: number;
pending_migrations?: number;
download_bytes: number;
}
@@ -376,6 +382,8 @@ export interface ConsoleLine {
}
export const api = {
remoteConnection: () => invoke<RemoteConnection>("remote_connection"),
remoteConnect: (host: string) => invoke<RemoteConnection>("remote_connect", { host }),
realmProfiles: (id: string) => invoke<RealmProfiles>("realm_profiles", { id }),
realmSelect: (id: string, mode: RealmMode, restart: boolean) => invoke<RealmProfiles>("realm_select", { id, mode, restart }),
realmSimultaneous: (id: string, enabled: boolean) => invoke<RealmProfiles>("realm_simultaneous", { id, enabled }),
@@ -425,6 +433,7 @@ export const api = {
applyUpdate: (id: string, resolutions: Record<string, "keep" | "replace">, source?: string) =>
invoke<{ txn: UpdateTxn }>("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 }),
population: (id: string) => invoke<Population | null>("get_population", { id }),
stopSpawning: (id: string) => invoke<{ count: number }>("companions_stop_spawning", { id }),
takeOffline: (id: string) => invoke<{ count: number }>("companions_take_offline", { id }),
+6 -1
View File
@@ -46,6 +46,9 @@ add("AiPlayerbot.CoaLfgBots", "bool", ["CoA bots fill dungeon groups", "Боты
add("AiPlayerbot.RandomBotXPRate", "float", ["Bot experience multiplier", "Множитель опыта ботов", "Bot-Erfahrungsmultiplikator", "Multiplicateur d’expérience des bots", "Multiplicador de experiencia de bots", "机器人经验倍率"], ["1 uses the normal experience rate for random bots.", "1 — обычная скорость получения опыта случайными ботами.", "1 nutzt die normale Erfahrungsrate für Zufallsbots.", "1 conserve le gain d’expérience normal des bots aléatoires.", "1 usa la experiencia normal de bots aleatorios.", "1使用随机机器人的正常经验获取倍率。"], { min: 0 });
add("AiPlayerbot.FollowDistance", "float", ["Follow distance", "Дистанция следования", "Folgeabstand", "Distance de suivi", "Distancia de seguimiento", "跟随距离"], ["Distance bots maintain while following their owner.", "Расстояние до владельца при следовании.", "Abstand zum Besitzer beim Folgen.", "Distance maintenue en suivant le propriétaire.", "Distancia mantenida al seguir al dueño.", "跟随主人时保持的距离。"], { min: 0 });
const scaling = "CoAContentScaling.";
add(scaling + "LFG.AllowPartialGroups", "bool", ["Enter with the current party", "Входить текущим составом", "Mit aktueller Gruppe betreten", "Entrer avec le groupe actuel", "Entrar con el grupo actual", "以当前队伍进入"], ["Enter Dungeon Finder with 1–5 players without waiting for a full party. Requires group scaling. BotFill keeps filling empty slots.", "Вход через ЛФГ составом 1–5 игроков без ожидания полной группы. Требует скейлинга группы. BotFill продолжает заполнять свободные места.", "Dungeonbrowser mit 1–5 Spielern ohne volle Gruppe. Erfordert Gruppenanpassung. BotFill füllt freie Plätze.", "Entrée avec 1 à 5 joueurs sans attendre un groupe complet. Nécessite l’adaptation au groupe. BotFill remplit les places libres.", "Entrar con 1–5 jugadores sin esperar un grupo completo. Requiere ajuste al grupo. BotFill llena los huecos.", "以1至5名玩家进入,无需等待满员。需要队伍缩放。BotFill仍会填补空位。"]);
add(scaling + "World.Leech.Enable", "bool", ["Open-world life steal", "Отхил от урона в открытом мире", "Lebensraub in der offenen Welt", "Vol de vie en monde ouvert", "Robo de vida en mundo abierto", "开放世界吸血"], ["Heal from your damage to open-world creatures. Excludes players, their pets and instances. Requires the module; group scaling and solo assistance are optional.", "Восстанавливает здоровье от вашего урона существам открытого мира. Исключает игроков, их питомцев и инстансы. Требует включения модуля; скейлинг группы и соло-помощь необязательны.", "Heilt durch eigenen Schaden an Weltkreaturen. Ohne Spieler, deren Begleiter und Instanzen. Erfordert das Modul; Gruppenanpassung und Solohilfe sind optional.", "Soigne grâce aux dégâts aux créatures du monde ouvert. Exclut joueurs, familiers et instances. Nécessite le module ; adaptation au groupe et aide solo facultatives.", "Cura con tu daño a criaturas del mundo abierto. Excluye jugadores, mascotas e instancias. Requiere el módulo; ajuste al grupo y ayuda individual opcionales.", "对开放世界生物造成伤害时恢复生命。不适用于玩家、玩家宠物和副本。需要启用模块,队伍缩放和单人辅助可选。"]);
add(scaling + "World.Leech.Percent", "float", ["Life steal (%)", "Отхил от нанесённого урона (%)", "Lebensraub (%)", "Vol de vie (%)", "Robo de vida (%)", "吸血比例(%)"], ["Percentage of damage returned as health: 0–100. 10 means 10%. Requires open-world life steal. Overkill gives no extra healing.", "Процент урона, возвращаемый здоровьем: 0–100. Значение 10 означает 10%. Требует включения отхила в открытом мире. Избыточный урон при добивании не увеличивает отхил.", "Schadensanteil als Heilung: 0–100. 10 bedeutet 10%. Erfordert Welt-Lebensraub. Überzähliger Schaden heilt nicht zusätzlich.", "Pourcentage des dégâts rendu en vie : 0–100. 10 signifie 10%. Nécessite le vol de vie. Les dégâts excédentaires ne soignent pas davantage.", "Porcentaje del daño recuperado como salud: 0–100. 10 significa 10%. Requiere robo de vida. El daño excedente no aporta curación adicional.", "将伤害的0至100%转化为生命。10表示10%。需要启用吸血。过量伤害不会额外治疗。"], { min: 0, max: 100 });
add(scaling + "Difficulty.DamageMultiplier", "range", ["Enemy damage", "Урон противников", "Gegnerschaden", "Dégâts ennemis", "Daño enemigo", "敌人伤害"], ["Dungeon and raid damage after group scaling and solo assistance. 100% keeps the normal balance; lower is easier. Applies to everyone on this server. Does not change health, loot or instant-kill mechanics.", "Урон в подземельях и рейдах после скейлинга группы и соло-помощи. 100% — обычный баланс, ниже — легче. Действует для всех игроков сервера. Не меняет здоровье, добычу и механики мгновенной смерти.", "Schaden in Dungeons und Schlachtzügen nach Gruppenanpassung und Solohilfe. 100% ist normal, weniger ist leichter. Gilt für alle Spieler. Ändert weder Gesundheit noch Beute oder Soforttötungen.", "Dégâts en donjon et raid après adaptation au groupe et aide solo. 100% conserve l’équilibrage normal ; moins est plus facile. Pour tous les joueurs. Ne change ni la vie, ni le butin, ni les morts instantanées.", "Daño en mazmorras y bandas tras el ajuste del grupo y la ayuda individual. 100% mantiene el equilibrio normal; menos es más fácil. Para todos los jugadores. No cambia salud, botín ni muerte instantánea.", "队伍缩放和单人辅助后的地下城与团队副本伤害。100%为正常,降低后更容易。对全服玩家生效,不改变生命值、掉落或即死机制。"], { min: 0.25, max: 2 });
add(scaling + "SoloAssist.Mode", "enum", ["Solo assistance", "Помощь в соло", "Solohilfe", "Aide solo", "Ayuda individual", "单人辅助"], ["Additional damage reduction when the scaling target is one player.", "Дополнительное снижение урона, когда расчёт сложности рассчитан на одного игрока.", "Zusätzliche Schadensreduktion bei einem Skalierungsziel von einem Spieler.", "Réduction supplémentaire quand la difficulté est calculée pour un joueur.", "Reducción adicional cuando la dificultad se calcula para un jugador.", "难度目标为一名玩家时额外减伤。"], { options: [
{ value: "None", label: ["None", "Без помощи", "Keine", "Aucune", "Ninguna", "无"] },
@@ -170,7 +173,9 @@ for (const [category, categoryNames] of Object.entries(auctionCategories)) {
{ min: 0, max: 1000, advanced: true },
);
}
export function moduleField(key: string, locale: Locale): ModuleField | undefined {
export function moduleField(key: string, locale: Locale, metadata?: ModuleSetting["field"]): ModuleField | undefined {
const translated = locale !== "en" ? fields.find(f => f.key === key) : undefined;
if (metadata) return { title: translated ? text(translated.title, locale) : metadata.title, description: translated ? text(translated.description, locale) : metadata.description, type: metadata.type, category: metadata.group, advanced: false, min: metadata.min ?? undefined, max: metadata.max ?? undefined };
const field = fields.find(f => f.key === key);
if (field) return { ...field, title: text(field.title, locale), description: text(field.description, locale), category: "general", advanced: field.advanced ?? false, step: field.type === "range" ? 0.05 : undefined, options: field.options?.map(o => ({ value: o.value, label: text(o.label, locale) })) };
const existing = [...bots.settings, ...server.settings].find(s => s.key === key);
+26 -5
View File
@@ -1,6 +1,7 @@
import { useSyncExternalStore } from "react";
import { listen } from "@tauri-apps/api/event";
import { api, asUiError, type UiError, type UpdatePreview, type UpdateTxn } from "@/lib/api";
import { isUpdateCurrent } from "./serverUpdateStatus";
/**
* Server update status for the main screen and the navigation: checked when the app starts and every five minutes,
@@ -16,11 +17,13 @@ export interface ServerUpdateState {
error: string | null;
/** The full error of the last update attempt, for the Settings card. */
uiError: UiError | null;
stateError: UiError | null;
stateRevision: number;
/** How the last update ended; kept here so the Settings card can show it after the user left and came back. */
result: { committed: string } | { pending: UpdateTxn } | null;
}
const EMPTY: ServerUpdateState = { preview: null, available: false, checking: false, applying: false, step: null, percent: 0, error: null, uiError: null, result: null };
const EMPTY: ServerUpdateState = { preview: null, available: false, checking: false, applying: false, step: null, percent: 0, error: null, uiError: null, stateError: null, stateRevision: 0, result: null };
const states = new Map<string, ServerUpdateState>();
const listeners = new Set<() => void>();
export const CHECK_EVERY_MS = 5 * 60 * 1000;
@@ -37,10 +40,10 @@ export async function checkServerUpdate(id: string): Promise<void> {
set(id, { checking: true });
try {
const p = await api.checkUpdate(id);
set(id, { preview: p, available: p.to_version !== (p.from_version ?? ""), error: null });
set(id, { preview: p, available: !isUpdateCurrent(p), error: null });
} catch (e) {
// offline or no package published: keep what we knew and stay quiet
set(id, { error: asUiError(e).human.code });
// A cached offer is no longer safe after an update or failed recheck.
set(id, { preview: null, available: false, error: asUiError(e).human.code });
} finally {
set(id, { checking: false });
}
@@ -57,6 +60,20 @@ export function clearServerUpdateResult(id: string) {
set(id, { result: null, uiError: null });
}
export async function refreshServerUpdateState(id: string): Promise<UpdateTxn | null> {
try {
const pending = await api.pendingUpdate(id);
const current = get(id).result;
set(id, { stateError: null, stateRevision: get(id).stateRevision + 1,
...(pending ? { available: false, preview: null } : {}),
result: pending ? { pending } : current && "committed" in current ? current : null });
return pending;
} catch (e) {
set(id, { stateError: asUiError(e), stateRevision: get(id).stateRevision + 1, available: false, preview: null });
throw e;
}
}
/**
* Apply an update. Without options this is the main-screen button: the pending update, only when no file needs a
* decision. With options (the Settings card) the owner has already chosen what to do with each changed file and may
@@ -65,7 +82,8 @@ export function clearServerUpdateResult(id: string) {
*/
export async function applyServerUpdate(id: string, opts?: { choices: Record<string, "keep" | "replace">; source?: string }): Promise<boolean> {
const p = get(id).preview;
if (get(id).applying) return false;
const current = get(id);
if (current.applying || current.stateError || (current.result && "pending" in current.result)) return false;
if (!opts && (!p || p.conflicts.length > 0)) return false;
set(id, { applying: true, step: null, percent: 0, error: null, uiError: null, result: null });
let un: (() => void) | undefined;
@@ -84,6 +102,9 @@ export async function applyServerUpdate(id: string, opts?: { choices: Record<str
return false;
} finally {
un?.();
try {
await refreshServerUpdateState(id);
} catch { /* The state error remains visible and prevents another apply. */ }
set(id, { applying: false });
void checkServerUpdate(id);
}
+7
View File
@@ -0,0 +1,7 @@
import type { UpdatePreview } from "./api";
export function isUpdateCurrent(preview: UpdatePreview): boolean {
return preview.from_version === preview.to_version
&& preview.items.every((item) => item.action === "skip")
&& (preview.pending_migrations ?? (preview.migrations === 0 ? 0 : undefined)) === 0;
}
+5 -3
View File
@@ -24,7 +24,7 @@ function group(key: string, curated: boolean) {
/** Use the same settings screen as Companions, backed only by shipped SQUID options. */
export function squidSettingsView(items: ModuleSetting[], locale: Locale): SettingsView {
const settings: SettingView[] = items.filter(s => s.key !== "AiPlayerbot.Enabled" && !s.key.startsWith("PlayerbotsDatabase") && !s.key.startsWith("Playerbots.Updates.")).map(s => {
const field = moduleField(s.key, locale);
const field = moduleField(s.key, locale, s.field);
const type = field?.type === "bool" || field?.type === "int" || field?.type === "float" || field?.type === "enum" ? field.type : "string";
const decode = (raw: string): JsonValue => {
const value = raw.trim().replace(/^"|"$/g, "");
@@ -35,11 +35,13 @@ export function squidSettingsView(items: ModuleSetting[], locale: Locale): Setti
const value = decode(s.value), defaultValue = decode(s.default ?? s.value);
return {
key: s.key, type, title: field?.title ?? s.key, description: field?.description ?? s.doc,
category: group(s.key, !!field), advanced: !field || !!field.advanced,
category: s.field?.group ? "squid." + s.field.group : group(s.key, !!field), advanced: !field || !!field.advanced,
min: field?.min, max: field?.max, options: field?.options ?? [],
value, default: defaultValue, is_default: value === defaultValue, present: true, problem: null,
drift: false, restartRequired: "world", dangerous: false,
};
});
return { scope: "bots", categories: groups.map(g => ({ id: g.id, title: g.titles[languages.indexOf(locale)] })), settings, unknown_keys: 0, drift_keys: [], files: ["Core/configs/modules/playerbots.conf"] };
const categories = new Map(groups.map(g => [g.id, g.titles[languages.indexOf(locale)]]));
for (const item of items) if (item.field?.group) categories.set("squid." + item.field.group, categories.get("squid." + item.field.group) ?? item.field.group_title ?? item.field.group);
return { scope: "bots", categories: [...categories].map(([id, title]) => ({ id, title })), settings, unknown_keys: 0, drift_keys: [], files: ["Core/configs/modules/playerbots.conf"] };
}
+9 -6
View File
@@ -7,7 +7,7 @@ import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { useHuman, useT } from "@/i18n";
export function ClientCard({ serverId }: { serverId: string }) {
export function ClientCard({ serverId, remote = false }: { serverId: string; remote?: boolean }) {
const t = useT();
const human = useHuman();
const [info, setInfo] = useState<ClientInfo | null | undefined>(undefined);
@@ -33,6 +33,7 @@ export function ClientCard({ serverId }: { serverId: string }) {
const msg = await fn();
if (msg) setNote(msg);
await refresh();
void checkClient(serverId);
} catch (e) {
setError(asUiError(e));
} finally {
@@ -54,7 +55,7 @@ export function ClientCard({ serverId }: { serverId: string }) {
{info === undefined && <p className="mt-2 text-sm text-muted">{t("client.looking")}</p>}
{info === null && (
<>
<p className="mt-1 text-sm text-muted">{t("client.intro")}</p>
<p className="mt-1 text-sm text-muted">{t(remote ? "remote.clientIntro" : "client.intro")}</p>
<Button className="mt-4" onClick={() => setDialog("setup")} disabled={busy}>{t("btn.setupClient")}</Button>
</>
)}
@@ -65,7 +66,7 @@ export function ClientCard({ serverId }: { serverId: string }) {
<dt className="text-muted">{t("client.connectsTo")}</dt>
<dd>
{hosts.length ? hosts.filter(Boolean).join(", ") : "—"}
{pointsLocal ? <span className="ml-2 text-ok">{t("client.thisComputer")}</span> : <span className="ml-2 text-warn">{t("client.notThisServer")}</span>}
{!remote && (pointsLocal ? <span className="ml-2 text-ok">{t("client.thisComputer")}</span> : <span className="ml-2 text-warn">{t("client.notThisServer")}</span>)}
</dd>
<dt className="text-muted">{t("client.version")}</dt>
<dd>
@@ -74,27 +75,29 @@ export function ClientCard({ serverId }: { serverId: string }) {
: t("client.versionUntracked")}
{status?.update_available && <span className="ml-2 text-warn">{t("client.updateAvailable")}</span>}
</dd>
{!remote && <>
<dt className="text-muted">{t("client.addon")}</dt>
<dd>
{info.addon.installed ? (info.addon.version ? t("client.installedVersion", { v: info.addon.version }) : t("client.installed")) : t("client.addonNotInstalled")}
{info.addon.up_to_date === false && <span className="ml-2 text-warn">{t("client.updateAvailable")}</span>}
<span className="mt-1 block text-xs text-muted">{t("client.addonWhat")}</span>
</dd>
</>}
<dt className="text-muted">{t("client.otherAddons")}</dt>
<dd>{t("client.leftAsIs", { n: info.other_addons })}</dd>
</dl>
<div className="mt-4 flex flex-wrap gap-2">
{!pointsLocal && (
{!remote && !pointsLocal && (
<Button size="sm" disabled={busy} onClick={() => void run(async () => { await api.setRealmlist(serverId, "127.0.0.1"); return t("client.pointedNote"); })}>
{t("client.pointLocal")}
</Button>
)}
{(!info.addon.installed || info.addon.up_to_date === false) && (
{!remote && (!info.addon.installed || info.addon.up_to_date === false) && (
<Button size="sm" disabled={busy} onClick={() => void run(async () => { await api.installAddon(serverId); return t("client.addonNote"); })}>
{info.addon.installed ? t("client.updateAddon") : t("client.installAddon")}
</Button>
)}
{status?.update_available && (
{(status?.update_available || (remote && status?.managed)) && (
<Button size="sm" variant="primary" disabled={busy} onClick={() => setDialog("update")}>{t("client.upd.start")}</Button>
)}
{status && !status.managed && (
+2 -2
View File
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from "react";
import { open } from "@tauri-apps/plugin-dialog";
import { listen } from "@tauri-apps/api/event";
import { Check, Loader2 } from "lucide-react";
import { api, asUiError, type ClientDownloadCheck, type ClientPlan, type ClientStep, type UiError } from "@/lib/api";
import { api, asUiError, REMOTE_CLIENT_ID, type ClientDownloadCheck, type ClientPlan, type ClientStep, type UiError } from "@/lib/api";
import { formatBytes } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
@@ -261,7 +261,7 @@ export function ClientDialog(props: {
<span className="flex h-9 w-9 items-center justify-center rounded-full bg-ok/15 text-ok"><Check className="h-5 w-5" aria-hidden /></span>
<div>
<p className="font-medium">{mode === "setup" ? t("client.dl.done") : t("client.upd.done")}</p>
<p className="text-sm text-muted">{mode === "setup" ? t("client.dl.doneText") : t("client.upd.doneText")}</p>
<p className="text-sm text-muted">{mode === "setup" ? t(serverId === REMOTE_CLIENT_ID ? "remote.clientReady" : "client.dl.doneText") : t("client.upd.doneText")}</p>
</div>
</div>
<div className="mt-5 flex justify-end">
+1 -1
View File
@@ -145,7 +145,7 @@ export function ImportServer(props: {
{report.notes.map((n) => (
<p key={n} className="mt-3 text-sm text-warn">
{n}
{hasKey(n) ? t(n as Key) : n}
</p>
))}
+9 -8
View File
@@ -133,6 +133,7 @@ export function ModulesPage({ serverId, onChanged }: { serverId: string; onChang
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
<h2 className="font-semibold leading-tight">{m.name}</h2>
{m.version && <span className="ml-2 text-xs font-normal text-muted">{m.version}</span>}
<StatusBadge status={m.status} />
</div>
<p className="mt-1.5 line-clamp-2 text-sm text-muted">{m.description[locale] ?? m.description.en}</p>
@@ -210,7 +211,7 @@ function ModuleSettings({ serverId, module, onSaved }: { serverId: string; modul
async function save() {
const errors: Record<string, string> = {};
for (const [key, value] of Object.entries(edits)) {
const field = moduleField(key, locale);
const field = moduleField(key, locale, items?.find(item => item.key === key)?.field);
if (field && ["int", "float", "range"].includes(field.type)) {
const number = Number(value);
const message = !value.trim() || !Number.isFinite(number) ? t("set.enterNumber")
@@ -248,13 +249,13 @@ function ModuleSettings({ serverId, module, onSaved }: { serverId: string; modul
return next;
});
const available = items?.filter(s => s.key !== moduleEnableKey(module.id)) ?? [];
const advancedCount = available.filter(s => !auctionWeightKey(s.key) && (!moduleField(s.key, locale) || moduleField(s.key, locale)?.advanced)).length;
const advancedCount = available.filter(s => !auctionWeightKey(s.key) && (!moduleField(s.key, locale, s.field) || moduleField(s.key, locale, s.field)?.advanced)).length;
const visible = available.filter(s => {
if (module.id === "ah-bot" && auctionWeightKey(s.key)) return false;
const field = moduleField(s.key, locale);
const field = moduleField(s.key, locale, s.field);
if (!advanced && !query.trim() && (!field || field.advanced)) return false;
const title = field ? sx.title({ key: s.key, title: field.title }) : s.key;
const description = field ? sx.description({ key: s.key, description: field.description }) : s.doc;
const title = field ? (s.field ? field.title : sx.title({ key: s.key, title: field.title })) : s.key;
const description = field ? (s.field ? field.description : sx.description({ key: s.key, description: field.description })) : s.doc;
return `${title} ${description} ${s.key}`.toLocaleLowerCase(locale).includes(query.trim().toLocaleLowerCase(locale));
});
return (
@@ -278,9 +279,9 @@ function ModuleSettings({ serverId, module, onSaved }: { serverId: string; modul
{items && !visible.length && !available.some(s => module.id === "ah-bot" && auctionWeightKey(s.key)) && <p className="py-3 text-sm text-muted">{t(available.length ? "all.none" : "mod.noSettings")}</p>}
<ul className="divide-y divide-line">
{visible.map((s) => {
const field = moduleField(s.key, locale);
const title = field ? sx.title({ key: s.key, title: field.title }) : s.key;
const description = field ? sx.description({ key: s.key, description: field.description }) : s.doc;
const field = moduleField(s.key, locale, s.field);
const title = field ? (s.field ? field.title : sx.title({ key: s.key, title: field.title })) : s.key;
const description = field ? (s.field ? field.description : sx.description({ key: s.key, description: field.description })) : s.doc;
const value = edits[s.key] ?? s.value;
const normalized = canonicalModuleValue(s.key, value);
const options = field?.options ?? [];
+10
View File
@@ -274,6 +274,11 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
{transitioning ? (action === "stopping" ? t("btn.stoppingCaps") : t("btn.startingCaps")) : t("btn.start")}
</Button>
)}
{!running && upd.available && (
<Button variant="secondary" size="sm" disabled={transitioning || upd.applying} onClick={() => run("starting")}>
{t("btn.startWithoutUpdate")}
</Button>
)}
{running && (
<Button variant="ghost" size="sm" disabled={transitioning || upd.applying} onClick={() => run("restarting")}>
{t("btn.restart")}
@@ -333,6 +338,11 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
{t("btn.setupClient")}
</Button>
) : null}
{client && !jobBusy && (clientStatus?.update_available || job.phase === "choose") && (
<Button variant="secondary" size="sm" disabled={realmBusy || playing || upd.applying} onClick={() => void play()}>
{t("btn.playWithoutUpdate")}
</Button>
)}
</div>
</div>
{anyUp && !running && !transitioning && (
+86
View File
@@ -0,0 +1,86 @@
import { useEffect, useState } from "react";
import { Gauge, Settings } from "lucide-react";
import { api, asUiError, REMOTE_CLIENT_ID } from "@/lib/api";
import { checkClient, startClientPolling, useClientStatus } from "@/lib/clientUpdate";
import { ClientCard } from "@/screens/ClientCard";
import { ClientDialog, type ClientDialogMode } from "@/screens/ClientDialog";
import { AboutCard } from "@/screens/AboutCard";
import { LanguagePicker } from "@/components/LanguagePicker";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { useHuman, useT } from "@/i18n";
import { cn } from "@/lib/utils";
import logo from "@/assets/logo.png";
export function RemoteClient({ onHost }: { onHost: () => void }) {
const t = useT();
const human = useHuman();
const [page, setPage] = useState<"overview" | "settings">("overview");
const [host, setHost] = useState("");
const [savedHost, setSavedHost] = useState("");
const [loading, setLoading] = useState(true);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [note, setNote] = useState<string | null>(null);
const [revision, setRevision] = useState(0);
const [dialog, setDialog] = useState<ClientDialogMode | null>(null);
const { status } = useClientStatus(REMOTE_CLIENT_ID);
function fail(e: unknown) {
const err = asUiError(e);
setError(err.human.code === "unknown" ? err.technical : human(err.human).message);
}
useEffect(() => {
void api.remoteConnection().then(p => { setHost(p.host); setSavedHost(p.host); }).catch(fail).finally(() => setLoading(false));
return startClientPolling(REMOTE_CLIENT_ID);
}, []); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => { void checkClient(REMOTE_CLIENT_ID); }, [revision]);
async function save() {
setBusy(true); setError(null); setNote(null);
try {
const profile = await api.remoteConnect(host);
setHost(profile.host); setSavedHost(profile.host); setRevision(n => n + 1);
setNote(t("remote.saved"));
} catch (e) { fail(e); } finally { setBusy(false); }
}
async function launch() {
setBusy(true); setError(null); setNote(null);
try { await api.play(REMOTE_CLIENT_ID); } catch (e) { fail(e); } finally { setBusy(false); }
}
function play() {
if (!status?.linked) setDialog("setup");
else if (status.update_available) setDialog("update");
else void launch();
}
return <div className="flex h-full">
<nav className="flex w-60 shrink-0 flex-col border-r border-line bg-[#0b0c0e] p-3" aria-label={t("nav.main")}>
<div className="flex items-center gap-2 px-3 pb-4 pt-2 text-sm font-semibold tracking-wide text-gold"><img src={logo} alt="" className="h-7 w-7" />{t("app.name")}</div>
<ul className="flex flex-col gap-0.5">
{(["overview", "settings"] as const).map(id => { const Icon = id === "overview" ? Gauge : Settings; return <li key={id}>
<button onClick={() => setPage(id)} aria-current={page === id ? "page" : undefined} className={cn("flex h-10 w-full cursor-pointer items-center gap-3 rounded-md px-3 text-left text-[15px]", page === id ? "bg-white/[0.07] text-ink" : "text-muted hover:bg-white/5 hover:text-ink")}><Icon className="h-[18px] w-[18px]" aria-hidden />{t(id === "overview" ? "nav.overview" : "nav.settings")}</button>
</li>; })}
</ul>
<div className="mt-auto border-t border-line pt-3"><Button variant="ghost" size="sm" className="w-full justify-start" onClick={onHost}>{t("remote.hostInstead")}</Button></div>
</nav>
<main className="h-full flex-1 overflow-y-auto px-10 py-8">
{page === "settings" ? <><div className="flex items-center justify-between"><h1 className="text-2xl font-semibold">{t("nav.settings")}</h1><LanguagePicker /></div><AboutCard /></> : <>
<div className="flex items-center justify-between"><h1 className="text-2xl font-semibold">{t("welcome.connect.title")}</h1><LanguagePicker /></div>
<p className="mt-2 text-muted">{t("remote.intro")}</p>
<Card className="mt-6 p-6">
<form onSubmit={e => { e.preventDefault(); void save(); }}>
<label htmlFor="remote-host" className="font-semibold">{t("remote.address")}</label>
<p id="remote-host-hint" className="mt-1 text-sm text-muted">{t("remote.addressHint")}</p>
<div className="mt-4 flex gap-3"><input id="remote-host" aria-describedby="remote-host-hint" value={host} onChange={e => { setHost(e.target.value); setNote(null); }} disabled={loading || busy} placeholder="192.168.1.10" className="min-w-0 flex-1 rounded-md border border-line bg-card px-3 py-2" /><Button type="submit" disabled={loading || busy || !host.trim()}>{t("remote.save")}</Button></div>
</form>
<p className="mt-3 text-sm text-muted">{t("remote.accountHint")}</p>
<Button variant="primary" className="mt-4" disabled={loading || busy || !savedHost || host.trim() !== savedHost || status === null} onClick={play}>{t("btn.play")}</Button>
{status?.linked && status.update_available && <Button variant="secondary" className="mt-4 ml-3" disabled={loading || busy || !savedHost || host.trim() !== savedHost} onClick={() => void launch()}>{t("btn.playWithoutUpdate")}</Button>}
{note && <p className="mt-3 text-sm text-ok" role="status">{note}</p>}
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
</Card>
<ClientCard key={revision} serverId={REMOTE_CLIENT_ID} remote />
</>}
</main>
{dialog && <ClientDialog serverId={REMOTE_CLIENT_ID} mode={dialog} onClose={() => setDialog(null)} onChanged={() => setRevision(n => n + 1)} onPlayAnyway={() => void launch()} />}
</div>;
}
+67 -17
View File
@@ -1,7 +1,8 @@
import { useEffect, useState } from "react";
import { open } from "@tauri-apps/plugin-dialog";
import { ChevronDown, ChevronRight, Loader2 } from "lucide-react";
import { applyServerUpdate, clearServerUpdateResult, useServerUpdate } from "@/lib/serverUpdate";
import { applyServerUpdate, clearServerUpdateResult, refreshServerUpdateState, useServerUpdate } from "@/lib/serverUpdate";
import { isUpdateCurrent } from "@/lib/serverUpdateStatus";
import { api, asUiError, type UiError, type UpdatePreview, type UpdateTxn } from "@/lib/api";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
@@ -23,12 +24,14 @@ export function SettingsHome({ serverId }: { serverId: string }) {
const human = useHuman();
const [preview, setPreview] = useState<UpdatePreview | null>(null);
const [pending, setPending] = useState<UpdateTxn | null>(null);
const [localBusy, setBusy] = useState<"check" | "rollback" | null>(null);
const [pendingChecked, setPendingChecked] = useState(false);
const [pendingStateError, setPendingStateError] = useState<UiError | null>(null);
const [localBusy, setBusy] = useState<"check" | "rollback" | "retry" | null>(null);
// an update keeps running in the background when this tab is left, so its state is the shared one
const busy = upd.applying ? "update" : localBusy;
const progress = upd.applying ? { step: upd.step ?? "Starting", percent: upd.percent } : null;
const [localError, setError] = useState<UiError | null>(null);
const error = localError ?? upd.uiError;
const error = pendingStateError ?? localError ?? upd.uiError;
const [localDone, setDone] = useState<string | null>(null);
const done = upd.result && "committed" in upd.result ? t("upd.updatedTo", { v: upd.result.committed }) : localDone;
const [choices, setChoices] = useState<Record<string, "keep" | "replace">>({});
@@ -36,16 +39,36 @@ export function SettingsHome({ serverId }: { serverId: string }) {
const [source, setSource] = useState("");
useEffect(() => {
void api.pendingUpdate(serverId).then(setPending).catch(() => {});
let active = true;
setPendingChecked(false);
setPending(null);
setPreview(null);
setPendingStateError(null);
void api.pendingUpdate(serverId).then((txn) => {
if (active) { setPending(txn); setPendingChecked(true); }
}).catch((e) => { if (active) setPendingStateError(asUiError(e)); });
return () => { active = false; };
}, [serverId]);
// the update finished (possibly while another tab was open): drop the stale preview, show what is left to decide
// Every finished attempt refreshes the disk state, including failures in the background.
useEffect(() => {
if (!upd.result) return;
if (!upd.stateRevision) return;
setPreview(null);
if ("pending" in upd.result) setPending(upd.result.pending);
else void api.pendingUpdate(serverId).then(setPending).catch(() => {});
}, [upd.result, serverId]);
setPendingChecked(!upd.stateError);
setPendingStateError(upd.stateError);
if (!upd.stateError) setPending(upd.result && "pending" in upd.result ? upd.result.pending : null);
}, [upd.stateRevision, serverId]);
async function refreshPending() {
setPendingChecked(false);
try {
const txn = await refreshServerUpdateState(serverId);
setPending(txn);
setPendingStateError(null);
setPendingChecked(true);
return txn;
} catch (e) { setPendingStateError(asUiError(e)); throw e; }
}
async function check() {
setBusy("check");
@@ -54,6 +77,8 @@ export function SettingsHome({ serverId }: { serverId: string }) {
clearServerUpdateResult(serverId);
setPreview(null);
try {
const txn = await refreshPending();
if (txn) return;
const p = await api.checkUpdate(serverId, source.trim() || undefined);
setPreview(p);
setChoices(Object.fromEntries(p.conflicts.map((c) => [c, "keep" as const])));
@@ -65,6 +90,7 @@ export function SettingsHome({ serverId }: { serverId: string }) {
}
async function update() {
if (!pendingChecked || pendingStateError || pending) return;
setError(null);
setDone(null);
await applyServerUpdate(serverId, { choices, source: source.trim() || undefined });
@@ -81,6 +107,25 @@ export function SettingsHome({ serverId }: { serverId: string }) {
} catch (e) {
setError(asUiError(e));
} finally {
try { await refreshPending(); } catch { /* Keep the disk-state error visible. */ }
setBusy(null);
}
}
async function retryValidation(txn: UpdateTxn) {
setBusy("retry");
setError(null);
try {
const result = await api.retryUpdateValidation(serverId, txn.id);
if (result.state === "committed") {
setPending(null);
setPreview(null);
setDone(t("upd.updatedTo", { v: result.to_version }));
clearServerUpdateResult(serverId);
} else setPending(result);
} catch (e) { setError(asUiError(e)); }
finally {
try { await refreshPending(); } catch { /* Keep the disk-state error visible. */ }
setBusy(null);
}
}
@@ -100,7 +145,13 @@ export function SettingsHome({ serverId }: { serverId: string }) {
<p className="font-medium text-warn">
{pending.state === "needs-decision" ? t("upd.pendingBad") : t("upd.pendingUnfinished")}
</p>
<p className="mt-1 text-sm text-muted">{pending.message ?? t("upd.safeBack")}</p>
<p className="mt-1 whitespace-pre-wrap text-sm text-muted">{pending.message ?? t("upd.safeBack")}</p>
{pending.state === "needs-decision" && (
<Button className="mt-3 mr-3" size="sm" disabled={!!busy} onClick={() => void retryValidation(pending)}>
{busy === "retry" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
{t("upd.retryValidation")}
</Button>
)}
<p className="mt-1 text-sm text-muted">{t("upd.backNote")}</p>
<Button className="mt-3" size="sm" disabled={!!busy} onClick={() => void rollback(pending)}>
{busy === "rollback" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
@@ -144,28 +195,27 @@ export function SettingsHome({ serverId }: { serverId: string }) {
</div>
)}
{done && <p className="mt-4 text-sm text-ok" role="status">{done}</p>}
{done && pendingChecked && !pendingStateError && <p className="mt-4 text-sm text-ok" role="status">{done}</p>}
{error && (
<p className="mt-4 text-sm text-bad" role="alert">
{error.human.code === "unknown" ? error.technical : human(error.human).message}
</p>
)}
{preview && preview.from_version === preview.to_version && preview.items.every((i) => i.action === "skip") && (
// The same version with no file to change: the database scripts of this package are all in the ledger already.
{preview && isUpdateCurrent(preview) && (
<div className="mt-5 border-t border-line pt-4">
<p className="font-medium text-ok" role="status">{t("upd.current", { v: preview.to_version })}</p>
</div>
)}
{preview && !(preview.from_version === preview.to_version && preview.items.every((i) => i.action === "skip")) && (
{preview && !isUpdateCurrent(preview) && (
<div className="mt-5 border-t border-line pt-4">
<p className="font-medium">
{preview.from_version ? t("upd.availableFrom", { to: preview.to_version, from: preview.from_version }) : t("upd.available", { to: preview.to_version })}
</p>
<p className="mt-1 text-sm text-muted">
{preview.migrations > 0
? t("upd.summaryDb", { size: mb(preview.download_bytes), files: preview.items.filter((i) => i.action !== "skip").length, db: preview.migrations })
{(preview.pending_migrations ?? preview.migrations) > 0
? t("upd.summaryDb", { size: mb(preview.download_bytes), files: preview.items.filter((i) => i.action !== "skip").length, db: preview.pending_migrations ?? preview.migrations })
: t("upd.summary", { size: mb(preview.download_bytes), files: preview.items.filter((i) => i.action !== "skip").length })}
</p>
<ul className="mt-3 max-h-56 divide-y divide-line overflow-auto text-sm">
@@ -190,7 +240,7 @@ export function SettingsHome({ serverId }: { serverId: string }) {
</li>
))}
</ul>
<Button className="mt-4" variant="primary" disabled={!!busy} onClick={() => void update()}>
<Button className="mt-4" variant="primary" disabled={!!busy || !pendingChecked || !!pendingStateError || !!pending} onClick={() => void update()}>
{busy === "update" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
{t("upd.now")}
</Button>
+5 -2
View File
@@ -178,12 +178,15 @@ export function SettingsPage(props: { serverId: string; scope: Scope; botModule?
const [raw, setRaw] = useState<AllSetting[] | null>(null);
const [rawEdits, setRawEdits] = useState<Record<string, string>>({});
const [onlyChanged, setOnlyChanged] = useState(false);
const [squidVersion, setSquidVersion] = useState<string | null>(null);
const [cols, setCols] = useState<ModuleSetting[]>([]);
const [colEdits, setColEdits] = useState<Record<string, string>>({});
const load = useCallback(async () => {
try {
const v = squid ? squidSettingsView(await api.moduleSettings(serverId, "playerbots"), locale) : await api.settings(serverId, scope);
const data = squid ? await Promise.all([api.moduleSettings(serverId, "playerbots"), api.modulesList(serverId)]) : null;
if (data) setSquidVersion(data[1].find(module => module.id === "playerbots")?.version ?? null);
const v = data ? squidSettingsView(data[0], locale) : await api.settings(serverId, scope);
setView(v);
setDraft({});
setErrors({});
@@ -363,7 +366,7 @@ export function SettingsPage(props: { serverId: string; scope: Scope; botModule?
return (
<div className="max-w-3xl pb-24">
<h1 className="text-2xl font-semibold">{props.title}</h1>
<p className="mt-1 text-muted">{squid ? "SQUID’s Playerbots" : props.question}</p>
<p className="mt-1 text-muted">{squid ? `SQUID’s Playerbots${squidVersion ? " · " + squidVersion : ""}` : props.question}</p>
{scope === "bots" && !squid && <CompanionsCard serverId={serverId} />}
+21 -6
View File
@@ -1,20 +1,34 @@
import { FolderSearch, Download } from "lucide-react";
import { useState } from "react";
import { FolderSearch, Download, Server, Globe } from "lucide-react";
import { useT } from "@/i18n";
import logo from "@/assets/logo.png";
import { LanguagePicker } from "@/components/LanguagePicker";
export function Welcome({ onImport, onInstall, onBack }: { onImport: () => void; onInstall: () => void; onBack?: () => void }) {
export function Welcome({ onImport, onInstall, onConnect, onBack }: { onImport: () => void; onInstall: () => void; onConnect: () => void; onBack?: () => void }) {
const t = useT();
const [hosting, setHosting] = useState(false);
return (
<main className="relative flex h-full flex-col items-center justify-center px-8">
<LanguagePicker className="absolute right-6 top-5" />
<div className="mb-10 text-center">
<img src={logo} alt="" aria-hidden className="mx-auto mb-5 h-24 w-24 drop-shadow-[0_6px_24px_rgb(201_162_74/0.35)]" />
<h1 className="text-3xl font-semibold tracking-tight">{t("welcome.title")}</h1>
<p className="mt-2 text-muted">{t("welcome.subtitle")}</p>
<p className="mt-2 text-muted">{t(hosting ? "welcome.subtitle" : "welcome.roleSubtitle")}</p>
</div>
<div className="grid w-full max-w-3xl grid-cols-2 gap-5">
{!hosting ? <>
<button onClick={() => setHosting(true)} className="cursor-pointer rounded-card border border-line bg-card/90 p-7 text-left transition-colors hover:border-gold/60">
<Server className="mb-4 h-7 w-7 text-gold" aria-hidden />
<h2 className="text-lg font-semibold">{t("welcome.host.title")}</h2>
<p className="mt-1 text-sm text-muted">{t("welcome.host.text")}</p>
</button>
<button onClick={onConnect} className="cursor-pointer rounded-card border border-line bg-card/90 p-7 text-left transition-colors hover:border-gold/60">
<Globe className="mb-4 h-7 w-7 text-gold" aria-hidden />
<h2 className="text-lg font-semibold">{t("welcome.connect.title")}</h2>
<p className="mt-1 text-sm text-muted">{t("welcome.connect.text")}</p>
</button>
</> : <>
<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"
@@ -34,10 +48,11 @@ export function Welcome({ onImport, onInstall, onBack }: { onImport: () => void;
{t("welcome.import.text")}
</p>
</button>
</>}
</div>
{onBack && (
<button onClick={onBack} className="mt-8 cursor-pointer text-sm text-muted hover:text-ink">
{t("welcome.back")}
{(hosting || onBack) && (
<button onClick={hosting ? () => setHosting(false) : onBack} className="mt-8 cursor-pointer text-sm text-muted hover:text-ink">
{t(hosting ? "client.dl.back" : "welcome.back")}
</button>
)}
</main>
+17
View File
@@ -23,6 +23,11 @@ for (const [value, expected] of [["0", "None"], ["1", "Light"], ["2", "Full"], [
}
const difficulty = moduleField("CoAContentScaling.Difficulty.DamageMultiplier", "ru");
if (difficulty.type !== "range" || difficulty.min !== 0.25 || difficulty.max !== 2) throw new Error("Damage slider bounds disagree with the server");
for (const key of ["CoAContentScaling.LFG.AllowPartialGroups", "CoAContentScaling.World.Leech.Enable"]) {
if (moduleField(key, "ru")?.type !== "bool") throw new Error(`${key}: expected a toggle`);
}
const leech = moduleField("CoAContentScaling.World.Leech.Percent", "ru");
if (leech?.type !== "float" || leech.min !== 0 || leech.max !== 100 || leech.advanced) throw new Error("Life steal must use a visible percentage field from 0 to 100");
const sample = [
{ key: "AuctionHouseBot.ListProportion.CategoryWeapon.QualityNormal", value: "20", default: "10" },
{ key: "AuctionHouseBot.ListProportion.CategoryWeapon.QualityRare", value: "7", default: "5" },
@@ -62,3 +67,15 @@ for (const locale of ["en", "ru", "de", "fr", "es", "zh"]) {
if (view.categories.some(c => !c.title)) throw new Error("SQUID categories must be translated");
}
console.log("SQUID Bots view: typed values, upstream defaults, categories and hidden managed settings verified");
const upstream = squidSettingsView([{ key: "AiPlayerbot.FutureOption", value: "2.5", default: "1", doc: "old description", field: {key:"AiPlayerbot.FutureOption",type:"float",title:"Future option",description:"From the release JSON",group:"new-group",group_title:"New activity",min:0,max:3} }], "ru");
const future = upstream.settings[0];
if (future.title !== "Future option" || future.description !== "From the release JSON" || future.type !== "float" || future.min !== 0 || future.max !== 3 || future.advanced || future.category !== "squid.new-group" || upstream.categories.find(c=>c.id===future.category)?.title !== "New activity") throw new Error("New upstream JSON options must appear without handwritten definitions");
console.log("Upstream metadata: new fields, titles, ranges and arbitrary groups verified");
const localized = moduleField("AiPlayerbot.MaxRandomBots", "ru", { key:"AiPlayerbot.MaxRandomBots", type:"int", title:"Upstream English title", description:"Upstream English description", group:"population", min:10, max:1234 });
const original = moduleField("AiPlayerbot.MaxRandomBots", "ru");
if (localized.title !== original.title || localized.description !== original.description || localized.max !== 1234) throw new Error("Existing translations must survive upstream metadata while ranges stay current");
const localizedGroup = squidSettingsView([{key:"AiPlayerbot.MaxRandomBots",value:"100",default:"500",doc:"",field:{key:"AiPlayerbot.MaxRandomBots",type:"int",title:"English",description:"English",group:"population",group_title:"English population"}}],"ru");
if (localizedGroup.categories.find(c=>c.id==="squid.population")?.title !== "Население мира") throw new Error("Known groups must retain translated captions");
console.log("Existing setting/group translations retained with upstream English fallback");
+62
View File
@@ -0,0 +1,62 @@
import assert from "node:assert/strict";
import test from "node:test";
import { registerHooks } from "node:module";
let applyFailure = false;
let stateFailure = false;
let pending = null;
const calls = [];
globalThis.__hotfixApi = {
applyUpdate: async () => { calls.push("apply"); if (applyFailure) throw new Error("SQL failure"); return { txn: { state: "committed", to_version: "2" } }; },
pendingUpdate: async () => { calls.push("disk"); if (stateFailure) throw new Error("damaged journal"); return pending; },
checkUpdate: async () => ({ from_version: "2", to_version: "2", items: [], conflicts: [], migrations: 1, pending_migrations: 0 }),
};
registerHooks({ resolve(specifier, context, next) {
if (specifier === "react") return { shortCircuit: true, url: "data:text/javascript,export const useSyncExternalStore=(subscribe,getSnapshot)=>getSnapshot();" };
if (specifier === "@/lib/api") return { shortCircuit: true, url: "data:text/javascript,export const api=globalThis.__hotfixApi;export const asUiError=e=>({human:{code:'unknown'},technical:e.message});" };
if (specifier === "@tauri-apps/api/event") return { shortCircuit: true, url: "data:text/javascript,export const listen=async()=>()=>{};" };
if (specifier === "./serverUpdateStatus" && context.parentURL?.endsWith("/serverUpdate.ts")) return { shortCircuit: true, url: new URL("../src/lib/serverUpdateStatus.ts", import.meta.url).href };
return next(specifier, context);
} });
const { applyServerUpdate, refreshServerUpdateState, checkServerUpdate, useServerUpdate } = await import("../src/lib/serverUpdate.ts");
test("a failed update rereads its unfinished transaction from disk", async () => {
calls.length = 0;
applyFailure = true;
pending = { id: "interrupted", state: "failed", message: "Recovery required" };
assert.equal(await applyServerUpdate("failed-case", { choices: {} }), false);
assert.deepEqual(calls, ["apply", "disk"]);
assert.equal(await refreshServerUpdateState("failed-case"), pending);
});
test("unreadable state blocks another apply until a successful reread", async () => {
calls.length = 0;
applyFailure = false;
stateFailure = true;
await applyServerUpdate("corrupt-case", { choices: {} });
assert.equal(await applyServerUpdate("corrupt-case", { choices: {} }), false);
assert.deepEqual(calls, ["apply", "disk"]);
stateFailure = false;
pending = null;
assert.equal(await refreshServerUpdateState("corrupt-case"), null);
assert.equal(await applyServerUpdate("corrupt-case", { choices: {} }), true);
assert.deepEqual(calls, ["apply", "disk", "disk", "apply", "disk"]);
});
test("refresh after recovery returns the latest disk state, then its absence", async () => {
pending = { id: "recovery", state: "failed", message: "Restore failed at database verification" };
assert.equal(await refreshServerUpdateState("recovery-case"), pending);
pending = null;
assert.equal(await refreshServerUpdateState("recovery-case"), null);
});
test("a rejected recheck removes an earlier cached update offer", async () => {
const original = globalThis.__hotfixApi.checkUpdate;
try {
globalThis.__hotfixApi.checkUpdate = async () => ({ from_version: "0.261005.22", to_version: "0.261005.24", items: [], migrations: 1, pending_migrations: 1 });
await checkServerUpdate("stale-offer");
assert.equal(useServerUpdate("stale-offer").available, true);
globalThis.__hotfixApi.checkUpdate = async () => { throw new Error("Installed version is newer than package"); };
await checkServerUpdate("stale-offer");
assert.equal(useServerUpdate("stale-offer").available, false);
assert.equal(useServerUpdate("stale-offer").preview, null);
} finally { globalThis.__hotfixApi.checkUpdate = original; }
});
+18
View File
@@ -0,0 +1,18 @@
import assert from "node:assert/strict";
import test from "node:test";
import { isUpdateCurrent } from "../src/lib/serverUpdateStatus.ts";
const same = { from_version: "1", to_version: "1", items: [{ action: "skip" }], migrations: 10 };
test("same files and version cannot hide pending database repairs", () => {
assert.equal(isUpdateCurrent({ ...same, pending_migrations: 1 }), false);
assert.equal(isUpdateCurrent({ ...same, pending_migrations: 0 }), true);
});
test("unknown history is not presented as up to date", () => {
assert.equal(isUpdateCurrent(same), false);
assert.equal(isUpdateCurrent({ ...same, migrations: 0 }), true);
});
test("file changes and new releases remain available with no pending SQL", () => {
assert.equal(isUpdateCurrent({ ...same, pending_migrations: 0, items: [{ action: "replace" }] }), false);
assert.equal(isUpdateCurrent({ ...same, pending_migrations: 0, to_version: "2" }), false);
});