Phase 9: Player Mode screen for portable characters and host runtime in the app

Characters screen (realms, make portable, preflight with the projection warning, one-click Play,
status chips, saved versions, diagnostics), Tauri commands, runtime started and stopped with the
application, native pin recorded on make-portable, degraded state derived from stored projection,
history in words instead of session identifiers, live test for make-portable then arm.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Sonnet 5.5 committed 2026-10-07 17:04:58 +05:00
1 parent aab0c28e1a
commit 5abba832e5
11 files changed
+1054 -19

No files matched your search

+18 -5
View File
@@ -36,7 +36,7 @@ use super::super::compat::{self, CompatibilityReport, Inputs, Operation, Outcome
use super::super::error::PortableError;
use super::super::extension::ExtensionRegistry;
use super::super::ids::{CharacterId, SessionId};
use super::super::projection::{Decision, Oracle, SuppliedDecision};
use super::super::projection::{Decision, Oracle, ProgressionPin, SuppliedDecision};
use super::super::realm::knowledge::RealmKnowledge;
use super::super::realm::online::import_character_online_on;
use super::super::realm::profile::{probe_capabilities, with_remembered_progression};
@@ -441,7 +441,7 @@ impl PortableService {
// ---- views --------------------------------------------------------------------------------------------------------------------
fn realm_view(&self, id: &str) -> Res<RealmView> {
pub fn realm_view(&self, id: &str) -> Res<RealmView> {
let a = self.access(id)?;
let o = self.obs.get(id);
let caps = o.and_then(|o| o.caps.as_ref());
@@ -494,7 +494,7 @@ impl PortableService {
}
} else if behind || stale {
PlayStatus::UpdateRequired
} else if let Some(Verdict::Degraded) = self.verdicts.get(&(character, realm_id.to_string())) {
} else if projected.is_some() || self.verdicts.get(&(character, realm_id.to_string())) == Some(&Verdict::Degraded) {
PlayStatus::CompatWarning
} else {
PlayStatus::Ready
@@ -510,7 +510,7 @@ impl PortableService {
for m in self.host.server_mappings(c.character_id).unwrap_or_default() {
let Some(realm) = self.realms.iter().find(|r| r.id == m.server_id) else { continue };
let (status, behind, projected_level, rev, at) = self.copy_status(c.character_id, c.revision, &m.server_id);
let degraded = self.verdicts.get(&(c.character_id, m.server_id.clone())) == Some(&Verdict::Degraded);
let degraded = projected_level.is_some() || self.verdicts.get(&(c.character_id, m.server_id.clone())) == Some(&Verdict::Degraded);
copies.push(CopyView { realm_id: m.server_id.clone(), realm_name: realm.name.clone(), status, synced_revision: rev, behind, projected_level, degraded, updated_at: at });
}
let active = copies.iter().find(|x| matches!(x.status, PlayStatus::Playing | PlayStatus::Saving | PlayStatus::WaitingLogin | PlayStatus::Syncing)).cloned();
@@ -900,6 +900,13 @@ impl PortableService {
let _ = self.host.detach_realm_copy(made.character_id, realm_id);
return Err(e.into());
}
if let Ok(mut ra) = access.ra() {
if let Ok(caps) = self.capabilities(&access, &db, &mut ra, true) {
if let Some(p) = &caps.progression {
let _ = self.host.set_mapping_pin(made.character_id, realm_id, Some(&ProgressionPin::native(p, &caps.content_profile_hash)));
}
}
}
self.publish();
self.state().characters.into_iter().find(|c| c.id == made.character_id.to_string()).ok_or_else(|| fail("other", "The character was not registered."))
}
@@ -954,7 +961,7 @@ impl PortableService {
.owner
.list_revisions(cid)?
.into_iter()
.map(|r| HistoryEntry { revision: r.revision, at: r.created_at, source_realm: names.get(r.source_server_id.as_str()).map(|n| n.to_string()).unwrap_or(r.source_server_id), note: r.note })
.map(|r| HistoryEntry { revision: r.revision, at: r.created_at, source_realm: names.get(r.source_server_id.as_str()).map(|n| n.to_string()).unwrap_or(r.source_server_id), kind: HistoryKind::of(r.note.as_deref()) })
.collect();
out.sort_by(|a, b| b.revision.cmp(&a.revision));
Ok(out)
@@ -1003,6 +1010,12 @@ impl PortableService {
DiagnosticsReport { generated_at: now_text(), manager_version: env!("CARGO_PKG_VERSION").to_string(), realms, characters, errors: self.errors.iter().cloned().collect() }
}
/// What the interface needs to start the game for a realm: the installation id (when this Manager runs the server) and the address.
pub fn realm_launch_info(&self, realm_id: &str) -> Res<(Option<String>, String)> {
let a = self.access(realm_id)?;
Ok((a.install_id.clone(), a.address.clone()))
}
pub fn saved(&self, character: &str, realm_id: &str) -> Option<(u64, String)> {
let cid: CharacterId = character.parse().ok()?;
self.saved.get(&(cid, realm_id.to_string())).map(|s| (s.revision, s.at.clone()))
@@ -166,6 +166,30 @@ fn one_click_play_of_a_level_eighty_on_a_cap_sixty_realm_survives_navigation_a_r
let _ = (name, server);
}
#[test]
#[ignore]
fn a_character_made_portable_on_a_running_realm_is_armed_on_it_without_a_restart() {
let (Some(r), Some(sp), Some(jobs)) = (realms(), spec(), job_dir()) else { return };
reset_b(&r.b);
std::fs::create_dir_all(&jobs).unwrap();
let dir = tempfile::tempdir().unwrap();
let file = descriptor(dir.path());
let mut svc = PortableService::open(&dir.path().join("portable"), vec![]).unwrap();
svc.add_prepared_realm(&file).unwrap();
let server = Server::start(sp);
svc.tick();
svc.tick();
let local = svc.local_characters(REALM).unwrap();
let pick = local.iter().find(|c| c.eligible).expect("an eligible character on the realm");
let made = svc.make_portable(REALM, pick.token).unwrap();
let pre = svc.preflight(&made.id, REALM).unwrap();
assert_eq!(pre.step, Step::Arm, "the realm's own character is current: nothing to update, nothing to restart; {:?}", pre.notes);
svc.play(&made.id, REALM, None).unwrap();
assert_eq!(status(&svc), PlayStatus::WaitingLogin);
drop(server);
}
fn name_of_account(db: &crate::db::Db, id: u32) -> String {
sql(db, &format!("SELECT username FROM acore_auth.account WHERE id = {id}")).trim().to_string()
}
+35 -1
View File
@@ -149,7 +149,41 @@ pub struct HistoryEntry {
pub revision: u64,
pub at: String,
pub source_realm: String,
pub note: Option<String>,
pub kind: HistoryKind,
}
/// What a saved version came from, in words a player understands; internal session and checkpoint identifiers never leave the service.
#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum HistoryKind {
Created,
Play,
Other,
}
impl HistoryKind {
pub fn of(note: Option<&str>) -> Self {
match note {
Some("created") => Self::Created,
Some(n) if n.starts_with("session ") => Self::Play,
_ => Self::Other,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn history_notes_become_kinds_without_identifiers() {
assert_eq!(HistoryKind::of(Some("created")), HistoryKind::Created);
assert_eq!(HistoryKind::of(Some("session 01a11638-9ccf-7111-b5e9-124d1ecf84bb checkpoint 3")), HistoryKind::Play);
assert_eq!(HistoryKind::of(Some("re-export")), HistoryKind::Other);
assert_eq!(HistoryKind::of(None), HistoryKind::Other);
let json = serde_json::to_string(&HistoryEntry { revision: 2, at: "t".into(), source_realm: "r".into(), kind: HistoryKind::of(Some("session 01a11638-9ccf-7111-b5e9-124d1ecf84bb checkpoint 3")) }).unwrap();
assert!(!json.contains("01a1") && !json.contains("checkpoint"), "{json}");
}
}
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]