From c590b82d27193d31d19a6b56b44a17d95fcb63c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Tue, 6 Oct 2026 08:11:54 +0500 Subject: [PATCH] feat(portable): read-only export of offline characters from a realm (Phase 2) Reads one offline character out of a realm's characters database through the existing Db abstraction: fixed SQL with the local guid as the only (numeric) input, one consistent READ ONLY snapshot per character, hex-encoded text. Maps the approved minimal v1 scope to the portable model; refuses online, deleted, bot, active challenge/game mode/Manastorm and unknown-table cases. Adds the 163-table registry, the settings policy, "Make Portable" in one store transaction, and item mapping lifecycle with content identity (schema 2) so a recycled local item guid never inherits an old portable item. Recorded answers of a real MySQL drive the unit tests; live tests re-verify them, read-only enforcement and snapshot consistency on a disposable server. No realm database is written and nothing changes for existing installs. Co-Authored-By: Claude Sonnet 5.5 --- crates/coa-core/src/db.rs | 6 + crates/coa-core/src/portable/error.rs | 15 + crates/coa-core/src/portable/identity.rs | 51 ++ .../migrations/002_item_mapping_lifecycle.sql | 41 ++ crates/coa-core/src/portable/mod.rs | 2 + .../coa-core/src/portable/realm/blockers.rs | 92 +++ crates/coa-core/src/portable/realm/export.rs | 397 +++++++++++ crates/coa-core/src/portable/realm/live.rs | 179 +++++ crates/coa-core/src/portable/realm/mod.rs | 182 +++++ crates/coa-core/src/portable/realm/policy.rs | 102 +++ .../coa-core/src/portable/realm/registry.rs | 305 +++++++++ crates/coa-core/src/portable/realm/script.rs | 605 +++++++++++++++++ .../realm/testdata/characters-tables.txt | 163 +++++ .../realm/testdata/golden/export-1001.txt | 28 + .../realm/testdata/golden/export-1002.txt | 234 +++++++ .../realm/testdata/golden/export-1003.txt | 60 ++ .../realm/testdata/golden/export-1004.txt | 356 ++++++++++ .../realm/testdata/golden/export-1005.txt | 39 ++ .../realm/testdata/golden/export-1006.txt | 28 + .../realm/testdata/golden/export-1007.txt | 28 + .../realm/testdata/golden/export-1008.txt | 28 + .../realm/testdata/golden/export-1009.txt | 28 + .../realm/testdata/golden/export-1010.txt | 28 + .../realm/testdata/golden/export-1011.txt | 28 + .../realm/testdata/golden/export-1012.txt | 28 + .../portable/realm/testdata/golden/list.txt | 11 + .../portable/realm/testdata/golden/probe.txt | 265 ++++++++ .../portable/realm/testdata/realm-fixture.sql | 640 ++++++++++++++++++ crates/coa-core/src/portable/realm/tests.rs | 444 ++++++++++++ crates/coa-core/src/portable/store.rs | 450 +++++++++--- crates/coa-core/src/portable/store/tests.rs | 163 ++++- docs/PORTABLE_EXPORT.md | 96 +++ docs/PORTABLE_FORMAT.md | 25 +- tools/gen_portable_fixture.py | 199 ++++++ 34 files changed, 5236 insertions(+), 110 deletions(-) create mode 100644 crates/coa-core/src/portable/identity.rs create mode 100644 crates/coa-core/src/portable/migrations/002_item_mapping_lifecycle.sql create mode 100644 crates/coa-core/src/portable/realm/blockers.rs create mode 100644 crates/coa-core/src/portable/realm/export.rs create mode 100644 crates/coa-core/src/portable/realm/live.rs create mode 100644 crates/coa-core/src/portable/realm/mod.rs create mode 100644 crates/coa-core/src/portable/realm/policy.rs create mode 100644 crates/coa-core/src/portable/realm/registry.rs create mode 100644 crates/coa-core/src/portable/realm/script.rs create mode 100644 crates/coa-core/src/portable/realm/testdata/characters-tables.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1001.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1002.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1003.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1004.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1005.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1006.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1007.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1008.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1009.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1010.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1011.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/export-1012.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/list.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/golden/probe.txt create mode 100644 crates/coa-core/src/portable/realm/testdata/realm-fixture.sql create mode 100644 crates/coa-core/src/portable/realm/tests.rs create mode 100644 docs/PORTABLE_EXPORT.md create mode 100644 tools/gen_portable_fixture.py diff --git a/crates/coa-core/src/db.rs b/crates/coa-core/src/db.rs index 0024b7a..ef45b19 100644 --- a/crates/coa-core/src/db.rs +++ b/crates/coa-core/src/db.rs @@ -120,6 +120,12 @@ impl Db { Ok(Db { bin: PathBuf::new(), port: 3306, user, password: Secret(password), realm: crate::realms::state(root)?.active, container: Some(container) }) } + /// A database reached through explicitly given client tools. Used by tests against a disposable server; the + /// installation-based constructors above are what the Manager itself uses. + pub fn with_tools(bin: PathBuf, port: u16, user: &'static str, password: &str, realm: crate::realms::Mode) -> Db { + Db { bin, port, user, password: Secret(password.to_string()), realm, container: None } + } + pub fn for_realm(mut self, realm: crate::realms::Mode) -> Self { self.realm = realm; self } pub fn realm(&self) -> crate::realms::Mode { self.realm } diff --git a/crates/coa-core/src/portable/error.rs b/crates/coa-core/src/portable/error.rs index 0bf4127..fcba2c5 100644 --- a/crates/coa-core/src/portable/error.rs +++ b/crates/coa-core/src/portable/error.rs @@ -1,4 +1,5 @@ use super::ids::CharacterId; +use super::realm::Blocker; pub type Result = std::result::Result; @@ -29,6 +30,20 @@ pub enum PortableError { #[error("local item {local_item_guid} on server {server_id} is mapped twice for one character")] ItemGuidConflict { server_id: String, local_item_guid: u32 }, + #[error("local character {local_guid} on server {server_id} is already portable ({character})")] + AlreadyPortable { server_id: String, local_guid: u32, character: CharacterId }, + + #[error("this character cannot be made portable: {}", .0.iter().map(|b| b.to_string()).collect::>().join("; "))] + NotExportable(Vec), + #[error("there is no character {0} on this realm")] + NoSuchRealmCharacter(u32), + #[error("the realm database does not have the expected structure: {0}")] + SchemaMismatch(String), + #[error("could not read the realm: {0}")] + RealmRead(String), + #[error("the realm database is a {found} realm but a {expected} character was requested")] + WrongRealm { expected: String, found: String }, + #[error("invalid data: {0}")] Invalid(String), #[error("limit exceeded: {0}")] diff --git a/crates/coa-core/src/portable/identity.rs b/crates/coa-core/src/portable/identity.rs new file mode 100644 index 0000000..67ee0ab --- /dev/null +++ b/crates/coa-core/src/portable/identity.rs @@ -0,0 +1,51 @@ +//! Content identity of an item: what it *was* when it was mapped to a portable item id. +//! +//! Local item guids are recycled by the realm. A mapping is only trusted while the item behind the guid still has the +//! same identity. The identity covers the traits that cannot change during an item's life (entry, random property or +//! suffix, crafter); count, durability, enchantments and position change all the time and are deliberately left out. +//! Two different items that share all of these are interchangeable for mapping purposes. + +use sha2::{Digest, Sha256}; + +use super::ids::ContentId; + +const VERSION: &str = "v1"; + +pub fn item_identity(entry: &ContentId, random_property_id: i32, creator_name: Option<&str>) -> String { + let mut h = Sha256::new(); + h.update(VERSION.as_bytes()); + h.update([0]); + h.update(entry.to_string().as_bytes()); + h.update([0]); + h.update(random_property_id.to_be_bytes()); + h.update([0]); + h.update(creator_name.unwrap_or("").as_bytes()); + format!("{VERSION}:{}", hex::encode(&h.finalize()[..16])) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn entry(id: u64) -> ContentId { + ContentId::new("coa", "item", id).unwrap() + } + + #[test] + fn same_traits_same_identity_and_any_difference_changes_it() { + let base = item_identity(&entry(100), -5, Some("Smith")); + assert_eq!(base, item_identity(&entry(100), -5, Some("Smith"))); + assert_ne!(base, item_identity(&entry(101), -5, Some("Smith")), "another entry"); + assert_ne!(base, item_identity(&entry(100), -6, Some("Smith")), "another suffix"); + assert_ne!(base, item_identity(&entry(100), -5, Some("Other")), "another crafter"); + assert_ne!(base, item_identity(&entry(100), -5, None), "no crafter"); + assert!(base.starts_with("v1:") && base.len() == 3 + 32); + } + + #[test] + fn the_namespace_is_part_of_the_identity() { + let a = ContentId::new("coa", "item", 7).unwrap(); + let b = ContentId::new("mod:x", "item", 7).unwrap(); + assert_ne!(item_identity(&a, 0, None), item_identity(&b, 0, None)); + } +} diff --git a/crates/coa-core/src/portable/migrations/002_item_mapping_lifecycle.sql b/crates/coa-core/src/portable/migrations/002_item_mapping_lifecycle.sql new file mode 100644 index 0000000..bc01253 --- /dev/null +++ b/crates/coa-core/src/portable/migrations/002_item_mapping_lifecycle.sql @@ -0,0 +1,41 @@ +-- Schema 2: item mappings get a lifecycle and a content identity. +-- +-- A realm hands out item guids from a counter that restarts at MAX(guid)+1, so a guid freed by a deleted item can +-- be given to a different one. A bare guid -> portable item mapping would then attach the new item to the old +-- portable id. Now every mapping records what the item *was* (`entry`, `identity`) when it was mapped, an old +-- mapping is retired (kept for the record) instead of overwritten, and only one *active* mapping may exist per +-- portable item and per local guid. + +CREATE TABLE item_mapping_new ( + mapping_id INTEGER PRIMARY KEY AUTOINCREMENT, + character_id TEXT NOT NULL, + server_id TEXT NOT NULL, + portable_item_id TEXT NOT NULL, + local_item_guid INTEGER NOT NULL, + entry TEXT NOT NULL, + identity TEXT NOT NULL, + state TEXT NOT NULL CHECK (state IN ('active', 'retired')), + created_revision INTEGER NOT NULL, + confirmed_revision INTEGER NOT NULL, + retired_revision INTEGER, + retired_reason TEXT CHECK (retired_reason IS NULL OR retired_reason IN ('guid_reused', 'moved', 'absent', 'character_rebound')), + created_at TEXT NOT NULL, + updated_at TEXT NOT NULL, + CHECK ((state = 'active') = (retired_revision IS NULL)), + FOREIGN KEY (character_id, server_id) REFERENCES character_server_mapping(character_id, server_id) ON DELETE CASCADE +) STRICT; + +-- Schema-1 rows have no recorded identity: '' never matches a real identity, so they are re-verified, not trusted. +INSERT INTO item_mapping_new(character_id, server_id, portable_item_id, local_item_guid, entry, identity, state, + created_revision, confirmed_revision, created_at, updated_at) +SELECT character_id, server_id, portable_item_id, local_item_guid, '', '', 'active', 1, 1, + strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), strftime('%Y-%m-%dT%H:%M:%fZ', 'now') +FROM item_mapping; + +DROP TABLE item_mapping; +ALTER TABLE item_mapping_new RENAME TO item_mapping; + +-- UNIQUE(character_id, server_id, local_item_guid) and one active mapping per portable item - for active rows. +CREATE UNIQUE INDEX item_mapping_active_item ON item_mapping(character_id, server_id, portable_item_id) WHERE state = 'active'; +CREATE UNIQUE INDEX item_mapping_active_guid ON item_mapping(character_id, server_id, local_item_guid) WHERE state = 'active'; +CREATE INDEX item_mapping_lookup ON item_mapping(character_id, server_id, state); diff --git a/crates/coa-core/src/portable/mod.rs b/crates/coa-core/src/portable/mod.rs index 7d4344f..160a649 100644 --- a/crates/coa-core/src/portable/mod.rs +++ b/crates/coa-core/src/portable/mod.rs @@ -8,8 +8,10 @@ pub mod collection; pub mod error; +pub mod identity; pub mod ids; pub mod model; +pub mod realm; pub mod snapshot; pub mod store; pub mod versions; diff --git a/crates/coa-core/src/portable/realm/blockers.rs b/crates/coa-core/src/portable/realm/blockers.rs new file mode 100644 index 0000000..380b77a --- /dev/null +++ b/crates/coa-core/src/portable/realm/blockers.rs @@ -0,0 +1,92 @@ +//! Reasons a realm character cannot be made portable (or exported) right now. + +use std::fmt; + +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub enum Blocker { + /// `characters.online` is set: the realm holds newer state in memory than in the database. Phase 2 exports offline + /// characters only; log the character out (or stop the realm) first. After a crash the flag can be stale. + Online, + /// The character is in the realm's "deleted characters" state. + Deleted, + /// Bots (`COABOT*`) and the Manager's own account are never portable. + BotAccount, + /// A challenge is in progress (`coa_character_challenge`). + ActiveChallenge, + /// A game mode such as hardcore is set (`coa_character_gamemode.gameMode <> 0`). + ActiveGameMode, + /// A custom trial is in progress (`coa_custom_trial_active`). + ActiveCustomTrial, + /// Manastorm caches are waiting for bag space (`ascension_manastorm_cache`): they name item guids that would be + /// orphaned by the move. + PendingManastormCaches, + /// A table this Manager does not know holds rows of this character: exporting would silently leave them behind. + UnclassifiedState(String), +} + +impl Blocker { + /// Stable identifier for the UI and for tests. + pub fn code(&self) -> &'static str { + match self { + Blocker::Online => "online", + Blocker::Deleted => "deleted", + Blocker::BotAccount => "bot_account", + Blocker::ActiveChallenge => "active_challenge", + Blocker::ActiveGameMode => "active_game_mode", + Blocker::ActiveCustomTrial => "active_custom_trial", + Blocker::PendingManastormCaches => "pending_manastorm_caches", + Blocker::UnclassifiedState(_) => "unclassified_state", + } + } + + /// Blockers that come from challenge / game mode / Manastorm state (decision D6). + pub fn is_challenge_state(&self) -> bool { + matches!(self, Blocker::ActiveChallenge | Blocker::ActiveGameMode | Blocker::ActiveCustomTrial | Blocker::PendingManastormCaches) + } +} + +impl fmt::Display for Blocker { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Blocker::Online => f.write_str("the character is online (or the realm did not log it out cleanly)"), + Blocker::Deleted => f.write_str("the character is deleted"), + Blocker::BotAccount => f.write_str("the character belongs to a bot or Manager account"), + Blocker::ActiveChallenge => f.write_str("a challenge is in progress"), + Blocker::ActiveGameMode => f.write_str("a game mode (such as hardcore) is active"), + Blocker::ActiveCustomTrial => f.write_str("a custom trial is in progress"), + Blocker::PendingManastormCaches => f.write_str("Manastorm caches are waiting to be delivered"), + Blocker::UnclassifiedState(table) => write!(f, "table `{table}` holds data of this character and is not known to this Manager"), + } + } +} + +/// Bot and Manager accounts, by the same rule the Manager already uses to hide them from the account list +/// (`accounts.rs`, `population.rs`). +pub fn is_internal_account(username: &str) -> bool { + let upper = username.to_ascii_uppercase(); + upper.starts_with("COABOT") || upper == "COAMANAGER" +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn internal_accounts_follow_the_managers_own_rule() { + for n in ["COABOTHOST1", "coabothost12", "COABOT", "COAMANAGER", "CoaManager"] { + assert!(is_internal_account(n), "{n}"); + } + for n in ["ALICE", "MYCOABOT", "COAMANAGER2", "BOT1", ""] { + assert!(!is_internal_account(n), "{n}"); + } + } + + #[test] + fn challenge_state_blockers_are_flagged_for_decision_d6() { + assert!(Blocker::ActiveChallenge.is_challenge_state()); + assert!(Blocker::ActiveGameMode.is_challenge_state()); + assert!(Blocker::PendingManastormCaches.is_challenge_state()); + assert!(!Blocker::Online.is_challenge_state()); + assert!(!Blocker::UnclassifiedState("x".into()).is_challenge_state()); + } +} diff --git a/crates/coa-core/src/portable/realm/export.rs b/crates/coa-core/src/portable/realm/export.rs new file mode 100644 index 0000000..51edab7 --- /dev/null +++ b/crates/coa-core/src/portable/realm/export.rs @@ -0,0 +1,397 @@ +//! Realm rows -> portable character. A pure function of one realm answer (`RawExport`): no database access here, so +//! it is tested against recorded answers of a real database. +//! +//! Nothing is copied blindly: every field is read by name, converted to the model's types, and the model is validated +//! (limits, container tree, ...) before it is returned. Items the realm itself would delete on load (orphans) are left +//! out with a warning instead of being exported. + +use std::collections::{BTreeMap, HashMap, HashSet}; + +use super::super::error::{PortableError, Result}; +use super::super::identity::item_identity; +use super::super::ids::{CharacterId, ContentId, PortableItemId, PortablePetId}; +use super::super::model::*; +use super::super::store::ItemObservation; +use super::super::versions::PORTABLE_CHARACTER_FORMAT_VERSION; +use super::blockers::{is_internal_account, Blocker}; +use super::policy::{classify_setting, Disposition, QUARANTINE_EXTENSION, SETTINGS_POLICY_VERSION}; +use super::script::{RawExport, Row}; + +/// Only the cosmetic bits of `playerFlags` are carried: hide helm (0x400) and hide cloak (0x800). +pub const COSMETIC_FLAG_MASK: u32 = 0x0C00; +/// Buyback slots are never persisted by the realm. +const BUYBACK_SLOTS: std::ops::RangeInclusive = 74..=85; + +pub struct ExportRequest<'a> { + pub ruleset: Ruleset, + pub local_guid: u32, + /// `None` = a new portable character (new UUIDv7); `Some` = a re-export of an existing one. + pub character_id: Option, + /// Active item mappings of that character on this realm: local item guid -> (portable item id, identity). + pub prior_items: &'a HashMap, +} + +#[derive(Debug)] +pub struct Exported { + pub model: PortableCharacter, + pub local_guid: u32, + /// The realm account that owns the character (never carried; used to describe the source). + pub account: u32, + /// One entry per exported item, ready for `Store::reconcile_item_mappings`. + pub observations: Vec, + /// Things that were left out or looked wrong; shown to the user, never silently dropped. + pub warnings: Vec, +} + +fn corrupt(msg: impl Into) -> Result { + Err(PortableError::CorruptSnapshot(msg.into())) +} + +/// Why this character cannot be exported now. Empty = it can. +pub fn blockers(raw: &RawExport) -> Result> { + let chars = raw.section("chars")?; + let row = chars.iter().next().ok_or_else(|| PortableError::NoSuchRealmCharacter(0))?; + let mut out = Vec::new(); + if row.u64("online")? != 0 { + out.push(Blocker::Online); + } + if row.u64("deleted")? != 0 { + out.push(Blocker::Deleted); + } + if row.opt_text("username")?.is_some_and(|u| is_internal_account(&u)) { + out.push(Blocker::BotAccount); + } + for (section, blocker) in [ + ("block:challenge", Blocker::ActiveChallenge), + ("block:gamemode", Blocker::ActiveGameMode), + ("block:trial", Blocker::ActiveCustomTrial), + ("block:manastorm", Blocker::PendingManastormCaches), + ] { + if raw.has(section) && raw.section(section)?.iter().next().map(|r| r.u64("n")).transpose()?.unwrap_or(0) > 0 { + out.push(blocker); + } + } + for name in raw.names().filter(|n| n.starts_with("unclassified:")) { + let n = raw.section(name)?.iter().next().map(|r| r.u64("n")).transpose()?.unwrap_or(0); + if n > 0 { + out.push(Blocker::UnclassifiedState(name["unclassified:".len()..].to_string())); + } + } + out.sort_by_key(|b| b.code()); + Ok(out) +} + +pub fn build(raw: &RawExport, req: &ExportRequest<'_>) -> Result { + let chars = raw.section("chars")?; + let c = chars.iter().next().ok_or(PortableError::NoSuchRealmCharacter(req.local_guid))?; + if c.u32("guid")? != req.local_guid { + return corrupt("the realm answered for another character"); + } + let blocked = blockers(raw)?; + if !blocked.is_empty() { + return Err(PortableError::NotExportable(blocked)); + } + + let ns = req.ruleset.as_str(); + let content = |kind: &str, id: u64| ContentId::new(ns, kind, id); + let mut warnings = Vec::new(); + + let identity = Identity { + name: c.text("name")?, + race: content("race", c.u64("race")?)?, + class: content("class", c.u64("class")?)?, + gender: c.u8("gender")?, + appearance: Appearance { + skin: c.u8("skin")?, + face: c.u8("face")?, + hair_style: c.u8("hair_style")?, + hair_color: c.u8("hair_color")?, + facial_style: c.u8("facial_style")?, + }, + cosmetic_flags: c.u32("player_flags")? & COSMETIC_FLAG_MASK, + }; + + let progression = Progression { + level: c.u8("level")?, + xp: c.u32("xp")?, + money: c.u32("money")?, + honor: Honor { + arena_points: c.u32("arena_points")?, + total_honor: c.u32("total_honor")?, + today_honor: c.u32("today_honor")?, + yesterday_honor: c.u32("yesterday_honor")?, + total_kills: c.u32("total_kills")?, + today_kills: c.u16("today_kills")?, + yesterday_kills: c.u16("yesterday_kills")?, + }, + known_currencies: c.u64("known_currencies")?, + chosen_title: c.u32("chosen_title")?, + known_titles: c.text("known_titles")?, + explored_zones: c.text("explored_zones")?, + taxi_mask: c.text("taxi_mask")?, + bank_slots: c.u8("bank_slots")?, + stable_slots: c.u8("stable_slots")?, + watched_faction: c.u32("watched_faction")?, + action_bars_mask: c.u8("action_bars")?, + }; + + let build = Build { + spells: pairs(raw, "spells")?, + talents: pairs(raw, "talents")?, + skills: raw.section("skills")?.iter().map(|r| Ok(Skill { skill: r.u32("skill")?, value: r.u16("value")?, max: r.u16("max")? })).collect::>()?, + glyphs: raw + .section("glyphs")? + .iter() + .map(|r| Ok(GlyphSet { talent_group: r.u8("talent_group")?, glyphs: [r.u16("g1")?, r.u16("g2")?, r.u16("g3")?, r.u16("g4")?, r.u16("g5")?, r.u16("g6")?] })) + .collect::>()?, + talent_groups_count: c.u8("talent_groups")?, + active_talent_group: c.u8("active_group")?, + extra_bonus_talent_count: c.i32("extra_talents")?, + reset_talents_cost: c.u32("reset_cost")?, + }; + + let (items, observations) = items(raw, req, ns, &mut warnings)?; + + let quests = Quests { + active: raw + .section("quests")? + .iter() + .map(|r| { + Ok(ActiveQuest { + quest: r.u32("quest")?, + status: r.u8("status")?, + explored: r.u64("explored")? != 0, + timer: r.u32("timer")?, + mob_counts: [r.u16("mob1")?, r.u16("mob2")?, r.u16("mob3")?, r.u16("mob4")?], + item_counts: [r.u16("item1")?, r.u16("item2")?, r.u16("item3")?, r.u16("item4")?, r.u16("item5")?, r.u16("item6")?], + player_count: r.u16("player_count")?, + }) + }) + .collect::>()?, + rewarded: raw.section("rewarded")?.iter().map(|r| r.u32("quest")).collect::>()?, + }; + + let reputation = raw + .section("reputation")? + .iter() + .map(|r| Ok(ReputationEntry { faction: r.u32("faction")?, standing: r.i32("standing")?, flags: r.u32("flags")? })) + .collect::>()?; + let actions = raw + .section("actions")? + .iter() + .map(|r| Ok(ActionButton { spec: r.u8("spec")?, button: r.u8("button")?, action: r.u32("action")?, kind: r.u8("type")? })) + .collect::>()?; + + let pets = pets(raw, ns)?; + let (settings, quarantined) = settings(raw, req.ruleset)?; + + let mut client_data = BTreeMap::new(); + if let Some(r) = raw.section("macros")?.iter().next() { + client_data.insert(5u8, ClientBlob { time: r.u32("time")?, data: Bytes(r.bytes("data")?) }); + } + + let mut extensions = BTreeMap::new(); + if !quarantined.is_empty() { + // BTreeMap -> deterministic bytes, so an unchanged quarantine has an unchanged hash + let payload = serde_json::to_vec(&quarantined)?; + extensions.insert(QUARANTINE_EXTENSION.to_string(), Extension::new(&SETTINGS_POLICY_VERSION.to_string(), 1, payload)); + warnings.push(format!("{} settings source(s) are not known gameplay state and were kept aside, not carried: {}", quarantined.len(), quarantined.keys().cloned().collect::>().join(", "))); + } + + let model = PortableCharacter { + format_version: PORTABLE_CHARACTER_FORMAT_VERSION, + character_id: req.character_id.unwrap_or_default(), + ruleset: req.ruleset, + content_namespace: ns.to_string(), + identity, + progression, + build, + items, + quests, + reputation, + actions, + pets, + settings, + client_data, + extensions, + } + .normalized(); + model.validate()?; + + Ok(Exported { model, local_guid: req.local_guid, account: c.u32("account")?, observations, warnings }) +} + +fn pairs(raw: &RawExport, section: &str) -> Result> { + raw.section(section)?.iter().map(|r| Ok((r.u32("spell")?, r.u8("spec_mask")?))).collect() +} + +fn numbers(text: &str, what: &str) -> Result> { + text.split_whitespace() + .map(|t| t.parse::().map_err(|_| PortableError::CorruptSnapshot(format!("{what}: {t:?} is not a number")))) + .collect() +} + +fn items(raw: &RawExport, req: &ExportRequest<'_>, ns: &str, warnings: &mut Vec) -> Result<(Vec, Vec)> { + let instances: HashMap> = raw.section("items")?.iter().map(|r| Ok((r.u32("guid")?, r))).collect::>()?; + let gifts: HashMap> = raw.section("gifts")?.iter().map(|r| Ok((r.u32("item_guid")?, r))).collect::>()?; + + // First pass: which inventory rows are usable at all. + struct Placed { + guid: u32, + bag: u32, + slot: u8, + } + let mut placed = Vec::new(); + for r in raw.section("inventory")?.iter() { + let (bag, slot, guid) = (r.u32("bag")?, r.u64("slot")?, r.u32("item")?); + let Ok(slot) = u8::try_from(slot) else { + warnings.push(format!("item {guid}: slot {slot} is out of range, left out")); + continue; + }; + if !instances.contains_key(&guid) { + warnings.push(format!("item {guid}: listed in the inventory but missing from item_instance (the realm would delete it), left out")); + continue; + } + if bag == 0 && BUYBACK_SLOTS.contains(&slot) { + warnings.push(format!("item {guid}: in a buyback slot, left out")); + continue; + } + placed.push(Placed { guid, bag, slot }); + } + let on_character: HashSet = placed.iter().filter(|p| p.bag == 0).map(|p| p.guid).collect(); + + let mut ids: HashMap = HashMap::new(); + let mut observations = Vec::new(); + let mut items = Vec::new(); + for p in &placed { + if p.bag != 0 && !on_character.contains(&p.bag) { + warnings.push(format!("item {}: its container {} is not on the character (the realm would delete it), left out", p.guid, p.bag)); + continue; + } + let r = instances[&p.guid]; + let entry = ContentId::new(ns, "item", r.u64("entry")?)?; + let random_property_id = r.i32("random_property")?; + let creator_name = if r.u64("creator_guid")? != 0 { r.opt_text("creator_name")?.filter(|n| !n.is_empty()) } else { None }; + let identity = item_identity(&entry, random_property_id, creator_name.as_deref()); + + // keep the portable id when this local guid is still the same item; a recycled guid gets a new one + let id = match req.prior_items.get(&p.guid) { + Some((id, prior_identity)) if *prior_identity == identity => *id, + _ => PortableItemId::new(), + }; + ids.insert(p.guid, id); + + let enchantment_numbers = numbers(&r.text("enchantments")?, "enchantments")?; + if enchantment_numbers.len() % 3 != 0 || enchantment_numbers.len() > 36 { + warnings.push(format!("item {}: unusual enchantment data ({} values)", p.guid, enchantment_numbers.len())); + } + let mut enchantments = Vec::new(); + for (slot, chunk) in enchantment_numbers.chunks_exact(3).take(12).enumerate() { + if chunk.iter().any(|v| *v != 0) { + let to = |v: i64| u32::try_from(v).map_err(|_| PortableError::CorruptSnapshot(format!("item {}: enchantment value {v} is out of range", p.guid))); + enchantments.push(Enchantment { slot: slot as u8, id: to(chunk[0])?, duration: to(chunk[1])?, charges: to(chunk[2])? }); + } + } + let charges: Vec = match r.opt_text("charges")? { + Some(text) => numbers(&text, "charges")?.into_iter().take(5).map(|v| i32::try_from(v).map_err(|_| PortableError::CorruptSnapshot("item charges out of range".into()))).collect::>()?, + None => Vec::new(), + }; + let gift = match gifts.get(&p.guid) { + Some(g) => Some(Gift { entry: ContentId::new(ns, "item", g.u64("entry")?)?, flags: g.u32("flags")? }), + None => None, + }; + + observations.push(ItemObservation { portable_item_id: id, local_item_guid: p.guid, entry: entry.clone(), identity }); + items.push(( + p.bag, + PortableItem { + id, + container: None, + slot: p.slot, + entry, + count: r.u32("count")?, + duration: r.i32("duration")?, + charges, + flags: r.u32("flags")?, + enchantments, + random_property_id, + durability: r.u32("durability")?, + played_time: r.u32("played_time")?, + text: r.opt_text("text")?.filter(|t| !t.is_empty()), + creator_name, + gift, + }, + )); + } + // containers are resolved after every id exists + let items = items + .into_iter() + .map(|(bag, mut item)| { + if bag != 0 { + item.container = ids.get(&bag).copied(); + } + item + }) + .collect(); + Ok((items, observations)) +} + +fn pets(raw: &RawExport, ns: &str) -> Result> { + let mut spells: HashMap> = HashMap::new(); + for r in raw.section("pet_spells")?.iter() { + spells.entry(r.u32("pet")?).or_default().push(PetSpell { spell: r.u32("spell")?, active: r.u8("active")? }); + } + let mut declined: HashMap = HashMap::new(); + for r in raw.section("pet_declined")?.iter() { + declined.insert(r.u32("id")?, [r.text("n1")?, r.text("n2")?, r.text("n3")?, r.text("n4")?, r.text("n5")?]); + } + raw.section("pets")? + .iter() + .map(|r| { + let number = r.u32("id")?; + Ok(PortablePet { + id: PortablePetId::new(), + entry: ContentId::new(ns, "creature", r.u64("entry")?)?, + model_id: r.u32("model")?, + created_by_spell: r.u32("created_by")?, + pet_type: r.u8("pet_type")?, + level: r.u16("level")?, + exp: r.u32("exp")?, + react_state: r.u8("react")?, + name: r.text("name")?, + renamed: r.u64("renamed")? != 0, + slot: r.u8("slot")?, + health: r.u32("health")?, + mana: r.u32("mana")?, + happiness: r.u32("happiness")?, + action_bar: r.text("abdata")?, + spells: spells.remove(&number).unwrap_or_default(), + declined_names: declined.remove(&number), + }) + }) + .collect() +} + +/// `(carried, quarantined)`. +fn settings(raw: &RawExport, ruleset: Ruleset) -> Result<(BTreeMap>, BTreeMap>)> { + let mut carried = BTreeMap::new(); + let mut quarantined = BTreeMap::new(); + for r in raw.section("settings")?.iter() { + let source = r.text("source")?; + let values: Vec = r + .text("data")? + .split_whitespace() + .map(|t| t.parse::().map_err(|_| PortableError::CorruptSnapshot(format!("settings {source}: {t:?} is not an unsigned integer")))) + .collect::>()?; + match classify_setting(&source, ruleset) { + Disposition::Carry => { + carried.insert(source, values); + } + Disposition::Quarantine => { + quarantined.insert(source, values); + } + Disposition::Drop => {} + } + } + Ok((carried, quarantined)) +} diff --git a/crates/coa-core/src/portable/realm/live.rs b/crates/coa-core/src/portable/realm/live.rs new file mode 100644 index 0000000..1628d21 --- /dev/null +++ b/crates/coa-core/src/portable/realm/live.rs @@ -0,0 +1,179 @@ +//! Tests against a **real, disposable** MySQL server. They are `#[ignore]`d: the normal `cargo test` never needs a +//! database. To run them, start a throw-away MySQL with the schema of a CoA characters + auth database and load +//! `testdata/realm-fixture.sql` into it (`tools/gen_portable_fixture.py` writes that file), then: +//! +//! ```text +//! COA_PORTABLE_LIVE="||" cargo test -p coa-core portable::realm::live -- --ignored --test-threads=1 +//! COA_PORTABLE_BLESS=1 ... # rewrite the recorded answers in testdata/golden/ instead of comparing +//! ``` +//! +//! Never point this at a real server: some tests modify the fixture rows (and restore them). + +use std::collections::HashMap; +use std::path::{Path, PathBuf}; + +use crate::db::Db; +use crate::portable::snapshot; +use crate::portable::store::Store; +use crate::realms::Mode; + +use super::script; +use super::*; + +const FIXTURE_GUIDS: std::ops::RangeInclusive = 1001..=1012; + +fn live_db() -> Option { + let spec = std::env::var("COA_PORTABLE_LIVE").ok()?; + let parts: Vec<&str> = spec.split('|').collect(); + assert_eq!(parts.len(), 3, "COA_PORTABLE_LIVE = ||"); + Some(Db::with_tools(PathBuf::from(parts[0]), parts[1].parse().expect("port"), "root", parts[2], Mode::Coa)) +} + +fn golden_dir() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")).join("src/portable/realm/testdata/golden") +} + +fn bless() -> bool { + std::env::var("COA_PORTABLE_BLESS").is_ok() +} + +/// Compare with (or, when blessing, rewrite) a recorded answer. Line endings are normalised so a Windows checkout +/// compares equal. +fn golden(name: &str, actual: &str) { + // the Windows mysql client prints CRLF + let actual = &actual.replace("\r\n", "\n"); + let path = golden_dir().join(name); + if bless() { + std::fs::create_dir_all(golden_dir()).unwrap(); + std::fs::write(&path, format!("{}\n", actual.trim_end())).unwrap(); + return; + } + let expected = std::fs::read_to_string(&path).unwrap_or_else(|_| panic!("missing golden file {name}; run once with COA_PORTABLE_BLESS=1")).replace("\r\n", "\n"); + assert_eq!(actual.trim_end(), expected.trim_end(), "the realm's answer for {name} changed (run with COA_PORTABLE_BLESS=1 if that is intended)"); +} + +fn probe_text(db: &Db) -> String { + db.query(&script::probe_sql(db.realm_schema(script::CHARACTERS_SCHEMA)).unwrap()).unwrap() +} + +#[test] +#[ignore] +fn record_or_verify_the_recorded_answers() { + let Some(db) = live_db() else { return }; + let probe_out = probe_text(&db); + golden("probe.txt", &probe_out); + let probe = script::parse_probe(&probe_out).unwrap(); + assert!(probe.missing_required().is_empty()); + + for guid in FIXTURE_GUIDS { + let queries = script::queries(guid, &probe).unwrap(); + let output = db.query(&script::snapshot_script(&queries)).unwrap(); + golden(&format!("export-{guid}.txt"), &output); + } + + // the character list also contains whatever else the disposable database holds; only the fixture rows are recorded + let listing = db.query(&script::list_sql(&probe)).unwrap(); + let ours: Vec<&str> = listing.lines().filter(|l| l.split('\t').next().and_then(|g| g.parse::().ok()).is_some_and(|g| FIXTURE_GUIDS.contains(&g))).collect(); + golden("list.txt", &ours.join("\n")); +} + +#[test] +#[ignore] +fn the_exporter_reads_through_the_real_db_layer() { + let Some(db) = live_db() else { return }; + let exported = export_character(&db, 1002, None, &HashMap::new()).unwrap(); + assert_eq!(exported.model.identity.name, "Geared"); + let encoded = snapshot::encode(&exported.model).unwrap(); + assert_eq!(snapshot::decode(&encoded.payload, Some(&encoded.content_hash)).unwrap(), exported.model); + // a character that is online is refused by the real layer too + assert!(matches!(export_character(&db, 1006, None, &HashMap::new()), Err(PortableError::NotExportable(b)) if b == vec![Blocker::Online])); + assert!(matches!(export_character(&db, 999_999, None, &HashMap::new()), Err(PortableError::NoSuchRealmCharacter(999_999)))); + // the listing agrees + let listing = inspect_characters(&db).unwrap(); + let find = |g: u32| listing.iter().find(|c| c.local_guid == g).unwrap(); + assert!(find(1001).eligible() && find(1012).eligible()); + assert_eq!(find(1006).blockers, vec![Blocker::Online]); + assert!(listing.iter().all(|c| c.local_guid != 1010), "bot accounts are not listed"); +} + +/// The real template characters of the schema fixture are genuine CoA characters (level 80, all 21 classes). +#[test] +#[ignore] +fn every_real_template_character_exports_and_roundtrips() { + let Some(db) = live_db() else { return }; + let mut exported = 0; + for guid in 112..=132u32 { + let result = export_character(&db, guid, None, &HashMap::new()); + let Ok(e) = result else { + panic!("template character {guid} did not export: {:?}", result.err()); + }; + let encoded = snapshot::encode(&e.model).unwrap(); + let back = snapshot::decode(&encoded.payload, Some(&encoded.content_hash)).unwrap(); + assert_eq!(back, e.model, "guid {guid}"); + assert_eq!(e.model.progression.level, 80); + // the template characters carry little more than their CoA gameplay state + assert!(!e.model.settings.is_empty() || !e.model.extensions.is_empty(), "guid {guid} exported without any CoA state"); + exported += 1; + } + assert_eq!(exported, 21); +} + +#[test] +#[ignore] +fn make_portable_registers_the_character_and_writes_nothing_to_the_realm() { + let Some(db) = live_db() else { return }; + let before = db.query("SELECT COUNT(*), IFNULL(SUM(money),0), IFNULL(SUM(level),0) FROM acore_characters.characters").unwrap(); + let items_before = db.query("SELECT COUNT(*) FROM acore_characters.item_instance").unwrap(); + + let mut store = Store::open_in_memory().unwrap(); + let profile = store.default_profile().unwrap(); + let made = make_portable(&db, &mut store, profile, "live-realm", 1002).unwrap(); + assert_eq!(made.revision, 1); + assert!(!made.warnings.is_empty(), "the orphaned items of the fixture are reported"); + assert_eq!(store.find_by_local("live-realm", 1002).unwrap(), Some(made.character_id)); + assert!(matches!(make_portable(&db, &mut store, profile, "live-realm", 1002), Err(PortableError::AlreadyPortable { .. }))); + + assert_eq!(db.query("SELECT COUNT(*), IFNULL(SUM(money),0), IFNULL(SUM(level),0) FROM acore_characters.characters").unwrap(), before); + assert_eq!(db.query("SELECT COUNT(*) FROM acore_characters.item_instance").unwrap(), items_before); +} + +#[test] +#[ignore] +fn the_snapshot_script_cannot_write() { + let Some(db) = live_db() else { return }; + let attempt = db.query("START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY;\nUPDATE acore_characters.characters SET money = 1 WHERE guid = 1012;\nCOMMIT;\n"); + let error = attempt.expect_err("a write inside the read-only snapshot must fail").to_string(); + assert!(error.to_lowercase().contains("read only") || error.to_lowercase().contains("read-only"), "{error}"); + assert_eq!(db.query("SELECT money FROM acore_characters.characters WHERE guid = 1012").unwrap(), "0"); +} + +/// All tables are read as of one moment: a write by someone else in the middle of the script is not seen. +#[test] +#[ignore] +fn the_snapshot_is_consistent_while_the_realm_keeps_writing() { + let Some(db) = live_db() else { return }; + db.query("UPDATE acore_characters.characters SET money = 100 WHERE guid = 1012").unwrap(); + let reader = { + let db = db.clone(); + std::thread::spawn(move || { + db.query( + "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; +START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY; + SELECT money FROM acore_characters.characters WHERE guid = 1012; +SELECT SLEEP(3); + SELECT money FROM acore_characters.characters WHERE guid = 1012; +COMMIT; +", + ) + .unwrap() + }) + }; + std::thread::sleep(std::time::Duration::from_millis(1200)); + db.query("UPDATE acore_characters.characters SET money = 777 WHERE guid = 1012").unwrap(); + let seen = reader.join().unwrap(); + let after = db.query("SELECT money FROM acore_characters.characters WHERE guid = 1012").unwrap(); + db.query("UPDATE acore_characters.characters SET money = 0 WHERE guid = 1012").unwrap(); + assert_eq!(after, "777", "the concurrent write really happened"); + let lines: Vec<&str> = seen.lines().collect(); + assert_eq!((lines.first().copied(), lines.last().copied()), (Some("100"), Some("100")), "both reads see the state at the start of the snapshot; saw {seen:?}"); +} diff --git a/crates/coa-core/src/portable/realm/mod.rs b/crates/coa-core/src/portable/realm/mod.rs new file mode 100644 index 0000000..1be7717 --- /dev/null +++ b/crates/coa-core/src/portable/realm/mod.rs @@ -0,0 +1,182 @@ +//! Phase 2: reading portable characters out of a realm's characters database. **Read-only, offline characters only.** +//! +//! * Goes through the Manager's existing [`Db`] abstraction (the bundled `mysql` client, or the same client inside a +//! Docker database container). No new connection type, no driver, no published port. +//! * Fixed SQL, one numeric input (the local guid); see [`script`]. +//! * One consistent read-only snapshot per character. +//! * A character that is online, deleted, a bot, in an active challenge/game mode/Manastorm state, or that has data in +//! a table this Manager does not know is **refused** (see [`Blocker`]), not exported half way. +//! +//! Writing into a realm is Phase 3 and will use prepared statements / the realm's own import path. + +pub mod blockers; +pub mod export; +pub mod policy; +pub mod registry; +pub mod script; + +use std::collections::HashMap; + +use crate::db::Db; +use crate::realms::Mode; + +use super::error::{PortableError, Result}; +use super::ids::{CharacterId, PortableItemId, ProfileId}; +use super::model::Ruleset; +use super::store::{RealmRegistration, Store}; + +pub use blockers::Blocker; +pub use export::{build, ExportRequest, Exported}; +pub use script::SchemaProbe; + +/// The ruleset a database belongs to is decided by which realm profile it is (`realms::Mode`), never by the caller. +pub fn ruleset_of(db: &Db) -> Ruleset { + match db.realm() { + Mode::Coa => Ruleset::Coa, + Mode::Wildcard => Ruleset::Wildcard, + } +} + +fn realm_error(e: crate::Error) -> PortableError { + let text = e.to_string(); + if text.contains("Unknown column") || text.contains("doesn't exist") || text.contains("Unknown table") { + PortableError::SchemaMismatch(text) + } else { + PortableError::RealmRead(text) + } +} + +/// The structure of the realm's characters schema (table and per-character column names only). +pub fn probe(db: &Db) -> Result { + let schema = db.realm_schema(script::CHARACTERS_SCHEMA); + let probe = script::parse_probe(&db.query(&script::probe_sql(schema)?).map_err(realm_error)?)?; + let missing = probe.missing_required(); + if !missing.is_empty() { + return Err(PortableError::SchemaMismatch(format!("these tables are missing: {}", missing.join(", ")))); + } + Ok(probe) +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct RealmCharacter { + pub local_guid: u32, + pub name: String, + pub race: u32, + pub class: u32, + pub level: u32, + pub account: u32, + pub username: Option, + /// Empty = can be made portable as far as can be told from the listing (unknown tables are checked at export). + pub blockers: Vec, +} + +impl RealmCharacter { + pub fn eligible(&self) -> bool { + self.blockers.is_empty() + } +} + +/// "Inspect realm characters": every character of a non-bot account, with the reasons it cannot be exported yet. +pub fn inspect_characters(db: &Db) -> Result> { + let probe = probe(db)?; + let output = db.query(&script::list_sql(&probe)).map_err(realm_error)?; + parse_listing(&output) +} + +pub fn parse_listing(output: &str) -> Result> { + let mut out = Vec::new(); + for line in output.lines().filter(|l| !l.is_empty()) { + let cells: Vec<&str> = line.split('\t').collect(); + if cells.len() != script::LIST_COLUMNS.len() { + return Err(PortableError::CorruptSnapshot(format!("character list row has {} columns", cells.len()))); + } + let num = |i: usize| cells[i].parse::().map_err(|_| PortableError::CorruptSnapshot(format!("character list: {:?} is not a number", cells[i]))); + let text = |i: usize| -> Result> { + match cells[i] { + "NULL" | "-" => Ok(None), + c => { + let hex = c.strip_prefix('x').ok_or_else(|| PortableError::CorruptSnapshot("character list: not a hex value".into()))?; + let bytes = hex::decode(hex).map_err(|_| PortableError::CorruptSnapshot("character list: invalid hex".into()))?; + Ok(Some(String::from_utf8(bytes).map_err(|_| PortableError::CorruptSnapshot("character list: not UTF-8".into()))?)) + } + } + }; + let username = text(7)?; + let mut blockers = Vec::new(); + if num(5)? != 0 { + blockers.push(Blocker::Online); + } + if num(8)? != 0 { + blockers.push(Blocker::Deleted); + } + if username.as_deref().is_some_and(blockers::is_internal_account) { + blockers.push(Blocker::BotAccount); + } + for (i, b) in [(9, Blocker::ActiveChallenge), (10, Blocker::ActiveGameMode), (11, Blocker::ActiveCustomTrial), (12, Blocker::PendingManastormCaches)] { + if num(i)? != 0 { + blockers.push(b); + } + } + out.push(RealmCharacter { + local_guid: u32::try_from(num(0)?).map_err(|_| PortableError::CorruptSnapshot("guid out of range".into()))?, + name: text(1)?.unwrap_or_default(), + race: num(2)? as u32, + class: num(3)? as u32, + level: num(4)? as u32, + account: num(6)? as u32, + username, + blockers, + }); + } + Ok(out) +} + +/// Read one character in one consistent snapshot. Returns the raw answer and the statements that produced it. +pub fn read_raw(db: &Db, local_guid: u32, probe: &SchemaProbe) -> Result { + let queries = script::queries(local_guid, probe)?; + let output = db.query(&script::snapshot_script(&queries)).map_err(realm_error)?; + script::parse_output(&output, &queries) +} + +/// "Export snapshot": the portable model of one offline character, plus the item observations that go with it. +/// `character_id` and `prior_items` are `None`/empty for a character that is not portable yet. +pub fn export_character(db: &Db, local_guid: u32, character_id: Option, prior_items: &HashMap) -> Result { + let probe = probe(db)?; + let raw = read_raw(db, local_guid, &probe)?; + export::build(&raw, &ExportRequest { ruleset: ruleset_of(db), local_guid, character_id, prior_items }) +} + +#[derive(Debug)] +pub struct MadePortable { + pub character_id: CharacterId, + pub revision: u64, + pub warnings: Vec, +} + +/// "Make Portable": export an offline character and register it in the local store (revision 1, bound to this realm, +/// items mapped) in one transaction. Writes only to the local store, never to the realm. +pub fn make_portable(db: &Db, store: &mut Store, profile: ProfileId, server_id: &str, local_guid: u32) -> Result { + if let Some(existing) = store.find_by_local(server_id, local_guid)? { + return Err(PortableError::AlreadyPortable { server_id: server_id.to_string(), local_guid, character: existing }); + } + let exported = export_character(db, local_guid, None, &HashMap::new())?; + register(store, profile, server_id, exported) +} + +/// The store half of [`make_portable`], separated so it can be tested with recorded realm answers. +pub fn register(store: &mut Store, profile: ProfileId, server_id: &str, exported: Exported) -> Result { + let character_id = store.register_realm_character(RealmRegistration { + profile, + model: exported.model, + source_server_id: server_id, + server_id, + local_guid: exported.local_guid, + observations: &exported.observations, + })?; + Ok(MadePortable { character_id, revision: 1, warnings: exported.warnings }) +} + +#[cfg(test)] +mod live; +#[cfg(test)] +mod tests; diff --git a/crates/coa-core/src/portable/realm/policy.rs b/crates/coa-core/src/portable/realm/policy.rs new file mode 100644 index 0000000..0c3bcc7 --- /dev/null +++ b/crates/coa-core/src/portable/realm/policy.rs @@ -0,0 +1,102 @@ +//! Which `character_settings` sources travel with a character (decision D2). +//! +//! `character_settings` is a free-form `(guid, source) -> integers` store used by the core and by modules; CoA keeps its +//! specialisation, talent builds and per-spec action bars there. The list is versioned data, not scattered `if`s: +//! +//! * `Carry` imported at the destination (known gameplay state); +//! * `Drop` never carried (bots, tests, high-risk bookkeeping); +//! * `Quarantine` kept in the canonical snapshot as an opaque extension but **not** imported anywhere; an unknown +//! source is never destroyed and never applied blindly. + +use super::super::model::Ruleset; + +/// Bump when the lists change; recorded with the quarantined extension. +pub const SETTINGS_POLICY_VERSION: u32 = 1; + +/// Extension namespace holding the quarantined sources. +pub const QUARANTINE_EXTENSION: &str = "coa:unlisted-settings"; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Disposition { + Carry, + Drop, + Quarantine, +} + +const CARRY_EXACT: &[&str] = &[ + "core.ascension", + "core.ascension_active_spec", + "core.ascension_starter", + "core.ascension_starter_live", + "core.ascension_reset_credits", + "core.ascension_slot.active", + "core.destiny_weaver", + "core.dynamic_xp.preset", + "core.runemaster.echoes", + "core.coa_prestige", + "core.coa_prestige_bar", + "core.coa_glory", +]; + +const CARRY_PREFIX: &[&str] = &["core.ascension_slot.", "core.ascension_build.", "core.ascension_bar.", "core.spell_charge.", "core.ascension.tutorial_"]; + +const DROP_PREFIX: &[&str] = &["coa.bot", "coa.gameplay_test", "coa.highrisk"]; + +pub fn classify_setting(source: &str, ruleset: Ruleset) -> Disposition { + if DROP_PREFIX.iter().any(|p| source.starts_with(p)) { + return Disposition::Drop; + } + if source == "core.wildcard" || source.starts_with("core.wildcard.") { + // Wildcard state only means something to the Wildcard ruleset. + return if ruleset == Ruleset::Wildcard { Disposition::Carry } else { Disposition::Quarantine }; + } + if CARRY_EXACT.contains(&source) || CARRY_PREFIX.iter().any(|p| source.starts_with(p)) { + return Disposition::Carry; + } + Disposition::Quarantine +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn known_coa_gameplay_state_is_carried() { + for s in [ + "core.ascension_active_spec", + "core.ascension_starter", + "core.ascension_slot.active", + "core.ascension_slot.2", + "core.ascension_slot.2.build.54", + "core.ascension_build.54", + "core.ascension_bar.54", + "core.spell_charge.804197", + "core.ascension.tutorial_verified", + "core.destiny_weaver", + ] { + assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Carry, "{s}"); + } + } + + #[test] + fn bots_tests_and_bookkeeping_are_dropped() { + for s in ["coa.bot.gear", "coa.bot_profile", "coa.gameplay_test", "coa.highrisk"] { + assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Drop, "{s}"); + } + } + + #[test] + fn unknown_sources_are_quarantined_never_dropped() { + for s in ["mod.someone.new_feature", "core.unheard_of", "coa.gear_pref_weapon", "core.ascensionx"] { + assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Quarantine, "{s}"); + } + } + + #[test] + fn wildcard_state_belongs_to_the_wildcard_ruleset() { + for s in ["core.wildcard", "core.wildcard.cards", "core.wildcard.scrolls.spec2"] { + assert_eq!(classify_setting(s, Ruleset::Wildcard), Disposition::Carry, "{s}"); + assert_eq!(classify_setting(s, Ruleset::Coa), Disposition::Quarantine, "{s}"); + } + } +} diff --git a/crates/coa-core/src/portable/realm/registry.rs b/crates/coa-core/src/portable/realm/registry.rs new file mode 100644 index 0000000..27f4d6c --- /dev/null +++ b/crates/coa-core/src/portable/realm/registry.rs @@ -0,0 +1,305 @@ +//! The table registry: every table of the characters database is classified, so that a new per-character table can +//! never be silently left out of an export (audit risk R5). The classification below is the audit's section 3 (163 +//! tables of the `coa-schema-fixture-20261005` schema) with the owner's decisions applied. +//! +//! * `Portable` exported in v1; +//! * `Deferred` portable later by decision (equipment sets, per-character wardrobe, personal bank, codex); +//! * `Collection` account-wide collections (Phase 6); +//! * `AccountLocal` account / realm-account state, never carried; +//! * `CharacterLocal` per-character state that is deliberately not portable (cooldowns, auras, mail links, ...); +//! * `Blocking` per-character state of an active challenge / game mode / Manastorm: while it exists the +//! character may not be made portable (decision D6); +//! * `Realm` realm operations (guilds, mail, auctions, logs, ...). +//! +//! At export time the tables of the *actual* schema are compared with this list. A table that is not listed and has a +//! per-character column holding rows of this character blocks the export instead of being ignored. + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum TableClass { + Portable, + Deferred, + Collection, + AccountLocal, + CharacterLocal, + Blocking, + Realm, +} + +pub fn classify(table: &str) -> Option { + TABLES.binary_search_by(|(name, _)| (*name).cmp(table)).ok().map(|i| TABLES[i].1) +} + +/// The tables of `actual` that the registry does not know (new modules, newer core). +pub fn unclassified<'a>(actual: impl IntoIterator) -> Vec { + actual.into_iter().filter(|t| classify(t).is_none()).map(str::to_string).collect() +} + +/// Column names that identify "this table holds data of one character". `account` is deliberately not here: account +/// state cannot be attributed to a single character. +pub fn is_character_column(column: &str) -> bool { + matches!( + column.to_ascii_lowercase().as_str(), + "guid" | "owner_guid" | "owner" | "character_guid" | "char_guid" | "characterguid" | "charguid" | "player_guid" | "playerguid" | "owner_id" | "bot_guid" | "character_id" + ) +} + +/// Sorted by name (binary search). +pub const TABLES: &[(&str, TableClass)] = &[ + ("account_appearance_collection", TableClass::Collection), + ("account_ascension_settings", TableClass::AccountLocal), + ("account_data", TableClass::AccountLocal), + ("account_instance_times", TableClass::AccountLocal), + ("account_tutorial", TableClass::AccountLocal), + ("account_vanity_collection", TableClass::Collection), + ("active_arena_season", TableClass::Realm), + ("addons", TableClass::Realm), + ("arena_team", TableClass::Realm), + ("arena_team_member", TableClass::Realm), + ("ascension_manastorm_bonus", TableClass::CharacterLocal), + ("ascension_manastorm_cache", TableClass::Blocking), + ("ascension_manastorm_clear", TableClass::CharacterLocal), + ("ascension_manastorm_loadout", TableClass::CharacterLocal), + ("ascension_manastorm_xp", TableClass::CharacterLocal), + ("ascension_player_ticket", TableClass::CharacterLocal), + ("ascension_player_ticket_message", TableClass::CharacterLocal), + ("auctionhouse", TableClass::Realm), + ("banned_addons", TableClass::Realm), + ("battleground_deserters", TableClass::Realm), + ("bugreport", TableClass::Realm), + ("calendar_events", TableClass::Realm), + ("calendar_invites", TableClass::Realm), + ("channels", TableClass::Realm), + ("channels_bans", TableClass::Realm), + ("channels_rights", TableClass::Realm), + ("character_account_data", TableClass::Portable), + ("character_achievement", TableClass::CharacterLocal), + ("character_achievement_offline_updates", TableClass::CharacterLocal), + ("character_achievement_progress", TableClass::CharacterLocal), + ("character_action", TableClass::Portable), + ("character_appearance", TableClass::Deferred), + ("character_appearance_outfit", TableClass::Deferred), + ("character_appearance_settings", TableClass::Deferred), + ("character_arena_stats", TableClass::CharacterLocal), + ("character_ascension_state", TableClass::CharacterLocal), + ("character_aura", TableClass::CharacterLocal), + ("character_banned", TableClass::CharacterLocal), + ("character_battleground_random", TableClass::CharacterLocal), + ("character_brew_of_the_month", TableClass::CharacterLocal), + ("character_coa_lfg_settings", TableClass::CharacterLocal), + ("character_declinedname", TableClass::CharacterLocal), + ("character_entry_point", TableClass::CharacterLocal), + ("character_equipmentsets", TableClass::Deferred), + ("character_gifts", TableClass::Portable), + ("character_glyphs", TableClass::Portable), + ("character_homebind", TableClass::CharacterLocal), + ("character_instance", TableClass::CharacterLocal), + ("character_inventory", TableClass::Portable), + ("character_pet", TableClass::Portable), + ("character_pet_declinedname", TableClass::Portable), + ("character_queststatus", TableClass::Portable), + ("character_queststatus_daily", TableClass::CharacterLocal), + ("character_queststatus_monthly", TableClass::CharacterLocal), + ("character_queststatus_rewarded", TableClass::Portable), + ("character_queststatus_seasonal", TableClass::CharacterLocal), + ("character_queststatus_weekly", TableClass::CharacterLocal), + ("character_reputation", TableClass::Portable), + ("character_settings", TableClass::Portable), + ("character_skills", TableClass::Portable), + ("character_social", TableClass::CharacterLocal), + ("character_spell", TableClass::Portable), + ("character_spell_cooldown", TableClass::CharacterLocal), + ("character_stats", TableClass::CharacterLocal), + ("character_talent", TableClass::Portable), + ("character_worldforged_loot", TableClass::CharacterLocal), + ("characters", TableClass::Portable), + ("chat_filter", TableClass::Realm), + ("coa_account_warchest", TableClass::AccountLocal), + ("coa_bot_gear_history", TableClass::CharacterLocal), + ("coa_bot_gear_queue", TableClass::CharacterLocal), + ("coa_challenge_completion", TableClass::CharacterLocal), + ("coa_challenge_failure", TableClass::CharacterLocal), + ("coa_character_challenge", TableClass::Blocking), + ("coa_character_condition", TableClass::CharacterLocal), + ("coa_character_fatigue", TableClass::CharacterLocal), + ("coa_character_gamemode", TableClass::Blocking), + ("coa_character_gamemode_lives", TableClass::CharacterLocal), + ("coa_character_looted_item", TableClass::CharacterLocal), + ("coa_character_objective", TableClass::CharacterLocal), + ("coa_character_survival", TableClass::CharacterLocal), + ("coa_custom_trial", TableClass::CharacterLocal), + ("coa_custom_trial_active", TableClass::Blocking), + ("coa_custom_trial_completion", TableClass::CharacterLocal), + ("coa_custom_trial_entry", TableClass::CharacterLocal), + ("coa_custom_trial_vote", TableClass::CharacterLocal), + ("coa_keepers_scroll_blessing", TableClass::Realm), + ("coa_squid_migrations", TableClass::Realm), + ("coa_wildcard_skill_card", TableClass::Collection), + ("coa_wildcard_skill_card_account", TableClass::Collection), + ("coa_wildcard_skill_card_pending", TableClass::Collection), + ("coa_wildcard_skill_card_purchase", TableClass::Collection), + ("coa_wildcard_specialization_cache", TableClass::AccountLocal), + ("corpse", TableClass::CharacterLocal), + ("creature_respawn", TableClass::Realm), + ("ethereal_bazaar_meta", TableClass::Realm), + ("ethereal_bazaar_stock", TableClass::Realm), + ("game_event_condition_save", TableClass::Realm), + ("game_event_save", TableClass::Realm), + ("gameobject_respawn", TableClass::Realm), + ("gm_subsurvey", TableClass::Realm), + ("gm_survey", TableClass::Realm), + ("gm_ticket", TableClass::Realm), + ("group_member", TableClass::Realm), + ("groups", TableClass::Realm), + ("guild", TableClass::Realm), + ("guild_bank_eventlog", TableClass::Realm), + ("guild_bank_item", TableClass::Realm), + ("guild_bank_right", TableClass::Realm), + ("guild_bank_tab", TableClass::Realm), + ("guild_eventlog", TableClass::Realm), + ("guild_member", TableClass::Realm), + ("guild_member_withdraw", TableClass::Realm), + ("guild_rank", TableClass::Realm), + ("highrisk_chest", TableClass::CharacterLocal), + ("highrisk_chest_item", TableClass::CharacterLocal), + ("instance", TableClass::Realm), + ("instance_reset", TableClass::Realm), + ("instance_saved_go_state_data", TableClass::Realm), + ("item_instance", TableClass::Portable), + ("item_loot_storage", TableClass::CharacterLocal), + ("item_refund_instance", TableClass::CharacterLocal), + ("item_soulbound_trade_data", TableClass::CharacterLocal), + ("lag_reports", TableClass::Realm), + ("lfg_data", TableClass::CharacterLocal), + ("log_arena_fights", TableClass::Realm), + ("log_arena_memberstats", TableClass::Realm), + ("log_encounter", TableClass::Realm), + ("log_money", TableClass::Realm), + ("mail", TableClass::Realm), + ("mail_items", TableClass::Realm), + ("mail_server_character", TableClass::Realm), + ("mail_server_template", TableClass::Realm), + ("mail_server_template_conditions", TableClass::Realm), + ("mail_server_template_items", TableClass::Realm), + ("mod_ascension_bank_item", TableClass::Deferred), + ("mod_ascension_bank_log", TableClass::Deferred), + ("mod_ascension_bank_money", TableClass::Deferred), + ("mod_ascension_bank_tab", TableClass::Deferred), + ("mod_coa_bot_guild_gather_orders", TableClass::CharacterLocal), + ("mod_craftsmans_codex", TableClass::Deferred), + ("pet_aura", TableClass::CharacterLocal), + ("pet_spell", TableClass::Portable), + ("pet_spell_cooldown", TableClass::CharacterLocal), + ("petition", TableClass::Realm), + ("petition_sign", TableClass::Realm), + ("player_anticheat_alert", TableClass::CharacterLocal), + ("playerbots_arena_team_names", TableClass::Realm), + ("playerbots_guild_names", TableClass::Realm), + ("playerbots_names", TableClass::Realm), + ("pool_quest_save", TableClass::Realm), + ("profanity_name", TableClass::Realm), + ("pvpstats_battlegrounds", TableClass::Realm), + ("pvpstats_players", TableClass::Realm), + ("quest_tracker", TableClass::CharacterLocal), + ("recovery_item", TableClass::CharacterLocal), + ("reserved_name", TableClass::Realm), + ("spam_reports", TableClass::Realm), + ("updates", TableClass::Realm), + ("updates_include", TableClass::Realm), + ("warden_action", TableClass::Realm), + ("world_state", TableClass::Realm), + ("worldstates", TableClass::Realm), +]; + +#[cfg(test)] +mod tests { + use super::*; + use std::collections::BTreeSet; + + const SCHEMA_TABLES: &str = include_str!("testdata/characters-tables.txt"); + + fn of(class: TableClass) -> BTreeSet<&'static str> { + TABLES.iter().filter(|(_, c)| *c == class).map(|(t, _)| *t).collect() + } + + #[test] + fn the_registry_is_sorted_and_free_of_duplicates() { + assert!(TABLES.windows(2).all(|w| w[0].0 < w[1].0), "TABLES must be strictly sorted for the binary search"); + } + + #[test] + fn every_table_of_the_real_schema_is_classified_and_nothing_is_stale() { + let schema: BTreeSet<&str> = SCHEMA_TABLES.lines().map(str::trim).filter(|l| !l.is_empty()).collect(); + assert_eq!(schema.len(), 163); + let missing: Vec<_> = schema.iter().filter(|t| classify(t).is_none()).collect(); + assert!(missing.is_empty(), "unclassified tables: {missing:?}"); + let stale: Vec<_> = TABLES.iter().map(|(t, _)| *t).filter(|t| !schema.contains(t)).collect(); + assert!(stale.is_empty(), "classified tables that are not in the schema: {stale:?}"); + } + + #[test] + fn a_new_module_table_is_reported_as_unclassified() { + assert_eq!(unclassified(["characters", "mod_shiny_new_thing", "item_instance"]), vec!["mod_shiny_new_thing".to_string()]); + } + + #[test] + fn the_v1_scope_is_exactly_the_approved_minimal_set() { + let expected: BTreeSet<&str> = [ + "characters", + "character_inventory", + "item_instance", + "character_gifts", + "character_spell", + "character_talent", + "character_skills", + "character_glyphs", + "character_reputation", + "character_queststatus", + "character_queststatus_rewarded", + "character_action", + "character_pet", + "pet_spell", + "character_pet_declinedname", + "character_settings", + "character_account_data", + ] + .into_iter() + .collect(); + assert_eq!(of(TableClass::Portable), expected); + } + + #[test] + fn deferred_and_blocking_tables_match_the_decisions() { + let deferred: BTreeSet<&str> = [ + "character_equipmentsets", + "character_appearance", + "character_appearance_outfit", + "character_appearance_settings", + "mod_ascension_bank_tab", + "mod_ascension_bank_item", + "mod_ascension_bank_money", + "mod_ascension_bank_log", + "mod_craftsmans_codex", + ] + .into_iter() + .collect(); + assert_eq!(of(TableClass::Deferred), deferred); + let blocking: BTreeSet<&str> = ["coa_character_challenge", "coa_character_gamemode", "coa_custom_trial_active", "ascension_manastorm_cache"].into_iter().collect(); + assert_eq!(of(TableClass::Blocking), blocking); + let collections: BTreeSet<&str> = ["account_appearance_collection", "account_vanity_collection"].into_iter().collect(); + assert!(collections.is_subset(&of(TableClass::Collection))); + assert_eq!(classify("mail"), Some(TableClass::Realm)); + assert_eq!(classify("character_aura"), Some(TableClass::CharacterLocal)); + assert_eq!(classify("account_data"), Some(TableClass::AccountLocal)); + assert_eq!(classify("nope"), None); + } + + #[test] + fn character_columns_are_recognised() { + for c in ["guid", "GUID", "owner_guid", "owner", "character_guid", "bot_guid"] { + assert!(is_character_column(c), "{c}"); + } + for c in ["account", "entry", "id", "item_guid", "name"] { + assert!(!is_character_column(c), "{c}"); + } + } +} diff --git a/crates/coa-core/src/portable/realm/script.rs b/crates/coa-core/src/portable/realm/script.rs new file mode 100644 index 0000000..ee1cff8 --- /dev/null +++ b/crates/coa-core/src/portable/realm/script.rs @@ -0,0 +1,605 @@ +//! The read-only SQL that is sent to a realm, and the parser of its answer. +//! +//! * **Fixed SQL.** Every statement is a literal in this file. The only input is the character's local guid, a `u32` +//! formatted as a number; no text from anywhere (names, settings, other databases) is ever put into SQL. The only +//! other identifiers, table and column names of unknown tables, come from `information_schema`, are checked as plain +//! identifiers and are only ever used in `SELECT COUNT(*)`. +//! * **One consistent snapshot.** All statements run in *one* `mysql` session inside +//! `START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY` at `REPEATABLE READ`: every table is read as of the same +//! moment, and the session cannot write. +//! * **Unambiguous output.** Every text or binary column is hex-encoded (`x` + hex), so tabs, newlines, quotes and +//! backslashes in names, item texts, settings or macros cannot confuse the parser. + +use std::collections::{BTreeMap, BTreeSet, HashMap}; + +use super::super::error::{PortableError, Result}; +use super::registry::{classify, is_character_column, TableClass}; + +/// Schema names as the Manager writes them; `Db` routes them to the Wildcard schemas when needed. +pub const CHARACTERS_SCHEMA: &str = "acore_characters"; +pub const AUTH_SCHEMA: &str = "acore_auth"; + +pub const SECTION_PREFIX: &str = "#T:"; + +/// Column names the schema probe asks about, to find per-character tables of unknown modules. +const CHARACTER_COLUMN_NAMES: &[&str] = &["guid", "owner_guid", "owner", "character_guid", "char_guid", "characterguid", "charguid", "player_guid", "playerguid", "owner_id", "bot_guid", "character_id"]; + +macro_rules! hex { + ($c:expr) => { + concat!("CONCAT('x',HEX(", $c, "))") + }; +} +macro_rules! hex_or_n { + ($c:expr) => { + concat!("IF(", $c, " IS NULL,'N',CONCAT('x',HEX(", $c, ")))") + }; +} + +fn plain_identifier(s: &str) -> bool { + crate::db::valid_identifier(s) +} + +// ---- schema probe ----------------------------------------------------------------------------------------------- + +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub struct SchemaProbe { + pub tables: BTreeSet, + /// table -> its per-character columns (see [`is_character_column`]). + pub character_columns: BTreeMap>, +} + +/// `schema` is the real schema name (`Db::realm_schema`); it appears in a string literal, which `Db` does not rewrite. +pub fn probe_sql(schema: &str) -> Result { + if !plain_identifier(schema) { + return Err(PortableError::Invalid(format!("invalid schema name {schema:?}"))); + } + let names = CHARACTER_COLUMN_NAMES.iter().map(|c| format!("'{c}'")).collect::>().join(","); + Ok(format!( + "SELECT 'T', table_name, '-' FROM information_schema.tables WHERE table_schema = '{schema}' AND table_type = 'BASE TABLE' \ + UNION ALL \ + SELECT 'C', table_name, column_name FROM information_schema.columns WHERE table_schema = '{schema}' AND LOWER(column_name) IN ({names}) ORDER BY 1, 2, 3;" + )) +} + +pub fn parse_probe(output: &str) -> Result { + let mut probe = SchemaProbe::default(); + for line in output.lines().filter(|l| !l.is_empty()) { + let cols: Vec<&str> = line.split('\t').collect(); + if cols.len() != 3 { + return Err(PortableError::CorruptSnapshot(format!("unexpected schema probe row {line:?}"))); + } + match cols[0] { + "T" => { + probe.tables.insert(cols[1].to_string()); + } + "C" => probe.character_columns.entry(cols[1].to_string()).or_default().push(cols[2].to_string()), + other => return Err(PortableError::CorruptSnapshot(format!("unexpected schema probe row kind {other:?}"))), + } + } + Ok(probe) +} + +impl SchemaProbe { + /// Portable tables the realm does not have: the schema is too old or too different to export from. + pub fn missing_required(&self) -> Vec<&'static str> { + super::registry::TABLES.iter().filter(|(_, c)| *c == TableClass::Portable).map(|(t, _)| *t).filter(|t| !self.tables.contains(*t)).collect() + } + + /// Tables this Manager does not know that carry a per-character column: `(table, column)`. + pub fn unclassified_character_tables(&self) -> Vec<(String, String)> { + self.character_columns + .iter() + .filter(|(table, _)| classify(table).is_none()) + .filter_map(|(table, columns)| columns.iter().find(|c| is_character_column(c)).map(|c| (table.clone(), c.clone()))) + .collect() + } + + pub fn has(&self, table: &str) -> bool { + self.tables.contains(table) + } +} + +// ---- queries ------------------------------------------------------------------------------------------------------ + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Query { + pub name: String, + pub columns: Vec<&'static str>, + pub sql: String, +} + +fn query(name: &str, columns: &[(&'static str, &str)], from: &str, guid: u32) -> Query { + let select = columns.iter().map(|(_, expr)| *expr).collect::>().join(", "); + Query { + name: name.to_string(), + columns: columns.iter().map(|(alias, _)| *alias).collect(), + sql: format!("SELECT {select} FROM {}", from.replace("{guid}", &guid.to_string())), + } +} + +/// All statements for one character, in a fixed order. `probe` decides which optional modules' tables are checked. +pub fn queries(guid: u32, probe: &SchemaProbe) -> Result> { + let mut out = vec![ + query( + "chars", + &[ + ("guid", "c.guid"), + ("account", "c.account"), + ("name", hex!("c.name")), + ("race", "c.race"), + ("class", "c.class"), + ("gender", "c.gender"), + ("level", "c.level"), + ("xp", "c.xp"), + ("money", "c.money"), + ("skin", "c.skin"), + ("face", "c.face"), + ("hair_style", "c.hairStyle"), + ("hair_color", "c.hairColor"), + ("facial_style", "c.facialStyle"), + ("bank_slots", "c.bankSlots"), + ("player_flags", "c.playerFlags"), + ("online", "c.online"), + ("taxi_mask", hex!("c.taximask")), + ("arena_points", "c.arenaPoints"), + ("total_honor", "c.totalHonorPoints"), + ("today_honor", "c.todayHonorPoints"), + ("yesterday_honor", "c.yesterdayHonorPoints"), + ("total_kills", "c.totalKills"), + ("today_kills", "c.todayKills"), + ("yesterday_kills", "c.yesterdayKills"), + ("chosen_title", "c.chosenTitle"), + ("known_currencies", "c.knownCurrencies"), + ("watched_faction", "c.watchedFaction"), + ("talent_groups", "c.talentGroupsCount"), + ("active_group", "c.activeTalentGroup"), + ("explored_zones", hex!("c.exploredZones")), + ("known_titles", hex!("c.knownTitles")), + ("action_bars", "c.actionBars"), + ("extra_talents", "c.extraBonusTalentCount"), + ("reset_cost", "c.resettalents_cost"), + ("stable_slots", "c.stable_slots"), + ("deleted", "IF(c.deleteDate IS NULL,0,1)"), + ("username", "IFNULL((SELECT CONCAT('x',HEX(a.username)) FROM acore_auth.account a WHERE a.id = c.account),'-')"), + ], + "acore_characters.characters c WHERE c.guid = {guid}", + guid, + ), + query("inventory", &[("bag", "ci.bag"), ("slot", "ci.slot"), ("item", "ci.item")], "acore_characters.character_inventory ci WHERE ci.guid = {guid} ORDER BY ci.bag, ci.slot, ci.item", guid), + query( + "items", + &[ + ("guid", "ii.guid"), + ("entry", "ii.itemEntry"), + ("count", "ii.count"), + ("duration", "ii.duration"), + ("charges", hex_or_n!("ii.charges")), + ("flags", "ii.flags"), + ("enchantments", hex!("ii.enchantments")), + ("random_property", "ii.randomPropertyId"), + ("durability", "ii.durability"), + ("played_time", "ii.playedTime"), + ("text", hex_or_n!("ii.text")), + ("creator_guid", "ii.creatorGuid"), + ("creator_name", "IFNULL((SELECT CONCAT('x',HEX(cc.name)) FROM acore_characters.characters cc WHERE cc.guid = ii.creatorGuid),'-')"), + ], + "acore_characters.character_inventory ci JOIN acore_characters.item_instance ii ON ii.guid = ci.item WHERE ci.guid = {guid} ORDER BY ii.guid", + guid, + ), + query("gifts", &[("item_guid", "g.item_guid"), ("entry", "g.entry"), ("flags", "g.flags")], "acore_characters.character_gifts g WHERE g.guid = {guid} ORDER BY g.item_guid", guid), + query("spells", &[("spell", "s.spell"), ("spec_mask", "s.specMask")], "acore_characters.character_spell s WHERE s.guid = {guid} ORDER BY s.spell", guid), + query("talents", &[("spell", "t.spell"), ("spec_mask", "t.specMask")], "acore_characters.character_talent t WHERE t.guid = {guid} ORDER BY t.spell", guid), + query("skills", &[("skill", "s.skill"), ("value", "s.value"), ("max", "s.`max`")], "acore_characters.character_skills s WHERE s.guid = {guid} ORDER BY s.skill", guid), + query( + "glyphs", + &[("talent_group", "g.talentGroup"), ("g1", "g.glyph1"), ("g2", "g.glyph2"), ("g3", "g.glyph3"), ("g4", "g.glyph4"), ("g5", "g.glyph5"), ("g6", "g.glyph6")], + "acore_characters.character_glyphs g WHERE g.guid = {guid} ORDER BY g.talentGroup", + guid, + ), + query("reputation", &[("faction", "r.faction"), ("standing", "r.standing"), ("flags", "r.flags")], "acore_characters.character_reputation r WHERE r.guid = {guid} ORDER BY r.faction", guid), + query( + "quests", + &[ + ("quest", "q.quest"), + ("status", "q.status"), + ("explored", "q.explored"), + ("timer", "q.timer"), + ("mob1", "q.mobcount1"), + ("mob2", "q.mobcount2"), + ("mob3", "q.mobcount3"), + ("mob4", "q.mobcount4"), + ("item1", "q.itemcount1"), + ("item2", "q.itemcount2"), + ("item3", "q.itemcount3"), + ("item4", "q.itemcount4"), + ("item5", "q.itemcount5"), + ("item6", "q.itemcount6"), + ("player_count", "q.playercount"), + ], + "acore_characters.character_queststatus q WHERE q.guid = {guid} ORDER BY q.quest", + guid, + ), + // the realm itself loads only rows with `active = 1` (`CHAR_SEL_CHARACTER_QUESTSTATUSREW`) + query("rewarded", &[("quest", "q.quest")], "acore_characters.character_queststatus_rewarded q WHERE q.guid = {guid} AND q.active = 1 ORDER BY q.quest", guid), + query("actions", &[("spec", "a.spec"), ("button", "a.button"), ("action", "a.action"), ("type", "a.`type`")], "acore_characters.character_action a WHERE a.guid = {guid} ORDER BY a.spec, a.button", guid), + query( + "pets", + &[ + ("id", "p.id"), + ("entry", "p.entry"), + ("model", "p.modelid"), + ("created_by", "p.CreatedBySpell"), + ("pet_type", "p.PetType"), + ("level", "p.level"), + ("exp", "p.exp"), + ("react", "p.Reactstate"), + ("name", hex!("p.name")), + ("renamed", "p.renamed"), + ("slot", "p.slot"), + ("health", "p.curhealth"), + ("mana", "p.curmana"), + ("happiness", "p.curhappiness"), + ("abdata", hex_or_n!("p.abdata")), + ], + "acore_characters.character_pet p WHERE p.owner = {guid} ORDER BY p.id", + guid, + ), + query( + "pet_spells", + &[("pet", "ps.guid"), ("spell", "ps.spell"), ("active", "ps.active")], + "acore_characters.pet_spell ps JOIN acore_characters.character_pet p ON p.id = ps.guid WHERE p.owner = {guid} ORDER BY ps.guid, ps.spell", + guid, + ), + query( + "pet_declined", + &[("id", "d.id"), ("n1", hex!("d.genitive")), ("n2", hex!("d.dative")), ("n3", hex!("d.accusative")), ("n4", hex!("d.instrumental")), ("n5", hex!("d.prepositional"))], + "acore_characters.character_pet_declinedname d WHERE d.owner = {guid} ORDER BY d.id", + guid, + ), + query("settings", &[("source", hex!("s.source")), ("data", hex!("s.data"))], "acore_characters.character_settings s WHERE s.guid = {guid} ORDER BY s.source", guid), + // macros are per-character account-data type 5 (`PER_CHARACTER_MACROS_CACHE`) + query("macros", &[("time", "d.`time`"), ("data", hex!("d.data"))], "acore_characters.character_account_data d WHERE d.guid = {guid} AND d.`type` = 5", guid), + ]; + + // Blockers of optional modules: only asked for when the module's table exists. + if probe.has("coa_character_challenge") { + out.push(query("block:challenge", &[("n", "COUNT(*)")], "acore_characters.coa_character_challenge WHERE guid = {guid}", guid)); + } + if probe.has("coa_character_gamemode") { + out.push(query("block:gamemode", &[("n", "COUNT(*)")], "acore_characters.coa_character_gamemode WHERE guid = {guid} AND gameMode <> 0", guid)); + } + if probe.has("coa_custom_trial_active") { + out.push(query("block:trial", &[("n", "COUNT(*)")], "acore_characters.coa_custom_trial_active WHERE guid = {guid}", guid)); + } + if probe.has("ascension_manastorm_cache") { + out.push(query("block:manastorm", &[("n", "COUNT(*)")], "acore_characters.ascension_manastorm_cache WHERE guid = {guid}", guid)); + } + // Per-character tables this Manager has never heard of. + for (table, column) in probe.unclassified_character_tables() { + if !plain_identifier(&table) || !plain_identifier(&column) { + return Err(PortableError::Invalid(format!("table or column name of an unknown table is not a plain identifier: {table}.{column}"))); + } + out.push(Query { + name: format!("unclassified:{table}"), + columns: vec!["n"], + sql: format!("SELECT COUNT(*) FROM acore_characters.`{table}` WHERE `{column}` = {guid}"), + }); + } + Ok(out) +} + +/// The whole script for one character: one session, one consistent read-only snapshot. +pub fn snapshot_script(queries: &[Query]) -> String { + let mut script = String::from("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nSTART TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY;\n"); + for q in queries { + script.push_str(&format!("SELECT '{SECTION_PREFIX}{}';\n{};\n", q.name, q.sql)); + } + script.push_str("COMMIT;\n"); + script +} + +// ---- listing characters ------------------------------------------------------------------------------------------- + +pub const LIST_COLUMNS: &[&str] = &["guid", "name", "race", "class", "level", "online", "account", "username", "deleted", "challenge", "gamemode", "trial", "manastorm"]; + +/// Characters of non-bot accounts, with the blocker facts that can be computed cheaply for all of them at once. +pub fn list_sql(probe: &SchemaProbe) -> String { + let exists = |table: &str, cond: &str| { + if probe.has(table) { + format!("EXISTS(SELECT 1 FROM acore_characters.{table} x WHERE x.guid = c.guid{cond})") + } else { + "0".to_string() + } + }; + format!( + "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;\n\ + START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY;\n\ + SELECT c.guid, CONCAT('x',HEX(c.name)), c.race, c.class, c.level, c.online, c.account, IFNULL(CONCAT('x',HEX(a.username)),'-'), IF(c.deleteDate IS NULL,0,1), {}, {}, {}, {} \ + FROM acore_characters.characters c LEFT JOIN acore_auth.account a ON a.id = c.account \ + WHERE a.username IS NULL OR (UPPER(a.username) NOT LIKE 'COABOT%' AND UPPER(a.username) <> 'COAMANAGER') \ + ORDER BY c.guid;\n\ + COMMIT;\n", + exists("coa_character_challenge", ""), + exists("coa_character_gamemode", " AND x.gameMode <> 0"), + exists("coa_custom_trial_active", ""), + exists("ascension_manastorm_cache", ""), + ) +} + +// ---- parsing ------------------------------------------------------------------------------------------------------ + +#[derive(Debug, Clone, Default)] +pub struct Rows { + pub columns: Vec<&'static str>, + pub rows: Vec>, +} + +#[derive(Debug, Clone, Default)] +pub struct RawExport { + sections: HashMap, +} + +impl RawExport { + pub fn section(&self, name: &str) -> Result<&Rows> { + self.sections.get(name).ok_or_else(|| PortableError::CorruptSnapshot(format!("the realm answer has no section {name}"))) + } + pub fn has(&self, name: &str) -> bool { + self.sections.contains_key(name) + } + pub fn names(&self) -> impl Iterator { + self.sections.keys().map(String::as_str) + } +} + +/// `output` is exactly what `Db::query` returned for [`snapshot_script`]. +pub fn parse_output(output: &str, queries: &[Query]) -> Result { + let by_name: HashMap<&str, &Query> = queries.iter().map(|q| (q.name.as_str(), q)).collect(); + let mut sections: HashMap = HashMap::new(); + let mut current: Option = None; + for line in output.lines() { + if let Some(name) = line.strip_prefix(SECTION_PREFIX) { + let query = by_name.get(name).ok_or_else(|| PortableError::CorruptSnapshot(format!("unexpected section {name:?} in the realm answer")))?; + if sections.insert(name.to_string(), Rows { columns: query.columns.clone(), rows: Vec::new() }).is_some() { + return Err(PortableError::CorruptSnapshot(format!("section {name} appears twice"))); + } + current = Some(name.to_string()); + continue; + } + if line.is_empty() { + continue; + } + let name = current.as_ref().ok_or_else(|| PortableError::CorruptSnapshot("data before the first section marker".into()))?; + let rows = sections.get_mut(name).expect("inserted with the marker"); + let cells: Vec = line.split('\t').map(str::to_string).collect(); + if cells.len() != rows.columns.len() { + return Err(PortableError::CorruptSnapshot(format!("section {name}: expected {} columns, got {}", rows.columns.len(), cells.len()))); + } + rows.rows.push(cells); + } + for q in queries { + if !sections.contains_key(&q.name) { + return Err(PortableError::CorruptSnapshot(format!("the realm answer is incomplete: section {} is missing", q.name))); + } + } + Ok(RawExport { sections }) +} + +impl Rows { + pub fn iter(&self) -> impl Iterator> { + self.rows.iter().map(|cells| Row { columns: &self.columns, cells }) + } + pub fn len(&self) -> usize { + self.rows.len() + } + pub fn is_empty(&self) -> bool { + self.rows.is_empty() + } +} + +#[derive(Clone, Copy)] +pub struct Row<'a> { + columns: &'a [&'static str], + cells: &'a [String], +} + +impl Row<'_> { + fn cell(&self, column: &str) -> Result<&str> { + let index = self.columns.iter().position(|c| *c == column).ok_or_else(|| PortableError::Invalid(format!("internal: no column {column}")))?; + Ok(&self.cells[index]) + } + + pub fn u64(&self, column: &str) -> Result { + let text = self.cell(column)?; + text.parse().map_err(|_| PortableError::CorruptSnapshot(format!("column {column}: {text:?} is not an unsigned integer"))) + } + + pub fn i64(&self, column: &str) -> Result { + let text = self.cell(column)?; + text.parse().map_err(|_| PortableError::CorruptSnapshot(format!("column {column}: {text:?} is not an integer"))) + } + + pub fn u32(&self, column: &str) -> Result { + let v = self.u64(column)?; + u32::try_from(v).map_err(|_| PortableError::CorruptSnapshot(format!("column {column}: {v} does not fit 32 bits"))) + } + + pub fn u16(&self, column: &str) -> Result { + let v = self.u64(column)?; + u16::try_from(v).map_err(|_| PortableError::CorruptSnapshot(format!("column {column}: {v} does not fit 16 bits"))) + } + + pub fn u8(&self, column: &str) -> Result { + let v = self.u64(column)?; + u8::try_from(v).map_err(|_| PortableError::CorruptSnapshot(format!("column {column}: {v} does not fit 8 bits"))) + } + + pub fn i32(&self, column: &str) -> Result { + let v = self.i64(column)?; + i32::try_from(v).map_err(|_| PortableError::CorruptSnapshot(format!("column {column}: {v} does not fit a signed 32-bit integer"))) + } + + /// Bytes of a hex column; `None` for SQL NULL (`NULL`, `N` or `-` markers). + pub fn opt_bytes(&self, column: &str) -> Result>> { + let text = self.cell(column)?; + if matches!(text, "NULL" | "N" | "-") { + return Ok(None); + } + let hex = text.strip_prefix('x').ok_or_else(|| PortableError::CorruptSnapshot(format!("column {column}: not a hex value")))?; + hex::decode(hex).map(Some).map_err(|_| PortableError::CorruptSnapshot(format!("column {column}: invalid hex"))) + } + + pub fn bytes(&self, column: &str) -> Result> { + Ok(self.opt_bytes(column)?.unwrap_or_default()) + } + + pub fn opt_text(&self, column: &str) -> Result> { + self.opt_bytes(column)? + .map(|b| String::from_utf8(b).map_err(|_| PortableError::CorruptSnapshot(format!("column {column}: not valid UTF-8")))) + .transpose() + } + + pub fn text(&self, column: &str) -> Result { + Ok(self.opt_text(column)?.unwrap_or_default()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn probe_with(tables: &[&str]) -> SchemaProbe { + SchemaProbe { tables: tables.iter().map(|t| t.to_string()).collect(), character_columns: BTreeMap::new() } + } + + fn script_for(guid: u32, probe: &SchemaProbe) -> String { + snapshot_script(&queries(guid, probe).unwrap()) + } + + #[test] + fn the_script_is_one_read_only_consistent_snapshot() { + let script = script_for(1002, &probe_with(&["coa_character_challenge", "coa_character_gamemode", "coa_custom_trial_active", "ascension_manastorm_cache"])); + let lines: Vec<&str> = script.lines().collect(); + assert_eq!(lines[0], "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;"); + assert_eq!(lines[1], "START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY;"); + assert_eq!(*lines.last().unwrap(), "COMMIT;"); + // every other statement is a plain SELECT + for line in &lines[2..lines.len() - 1] { + assert!(line.starts_with("SELECT "), "not a SELECT: {line}"); + } + } + + #[test] + fn nothing_in_the_script_can_write() { + let mut probe = probe_with(&["coa_character_challenge"]); + probe.character_columns.insert("mod_unknown_state".into(), vec!["guid".into()]); + let script = script_for(7, &probe).to_ascii_uppercase(); + for forbidden in ["INSERT ", "UPDATE ", "DELETE ", "REPLACE ", "DROP ", "ALTER ", "CREATE ", "TRUNCATE ", "GRANT ", "SET GLOBAL", "LOAD DATA", "INTO OUTFILE", "CALL ", "LOCK TABLES", "FOR UPDATE", "FOR SHARE"] { + assert!(!script.contains(forbidden), "the script contains {forbidden:?}"); + } + // the only SET is the isolation level, before the transaction starts + assert_eq!(script.matches("SET ").count(), 1); + } + + #[test] + fn the_only_input_is_the_guid_as_a_number() { + let a = script_for(1002, &probe_with(&[])); + let b = script_for(1003, &probe_with(&[])); + assert_eq!(a.replace("1002", "G"), b.replace("1003", "G"), "scripts for two guids differ only in the number"); + assert!(!a.contains("{guid}")); + assert!(a.contains("c.guid = 1002")); + } + + #[test] + fn optional_module_checks_follow_the_schema() { + let none = queries(1, &probe_with(&[])).unwrap(); + assert!(none.iter().all(|q| !q.name.starts_with("block:"))); + let all = queries(1, &probe_with(&["coa_character_challenge", "coa_character_gamemode", "coa_custom_trial_active", "ascension_manastorm_cache"])).unwrap(); + let names: Vec<&str> = all.iter().filter(|q| q.name.starts_with("block:")).map(|q| q.name.as_str()).collect(); + assert_eq!(names, ["block:challenge", "block:gamemode", "block:trial", "block:manastorm"]); + } + + #[test] + fn unknown_character_tables_get_a_count_query() { + let mut probe = probe_with(&[]); + probe.character_columns.insert("mod_unknown_state".into(), vec!["guid".into()]); + probe.character_columns.insert("item_instance".into(), vec!["guid".into(), "owner_guid".into()]); + probe.character_columns.insert("mod_other".into(), vec!["account".into()]); + let qs = queries(55, &probe).unwrap(); + let unknown: Vec<&Query> = qs.iter().filter(|q| q.name.starts_with("unclassified:")).collect(); + assert_eq!(unknown.len(), 1, "known tables and tables without a per-character column are not counted"); + assert_eq!(unknown[0].sql, "SELECT COUNT(*) FROM acore_characters.`mod_unknown_state` WHERE `guid` = 55"); + } + + #[test] + fn a_hostile_table_name_from_the_schema_is_refused() { + let mut probe = probe_with(&[]); + probe.character_columns.insert("x`; DROP TABLE characters; --".into(), vec!["guid".into()]); + assert!(queries(1, &probe).is_err()); + } + + #[test] + fn the_probe_names_the_schema_literally_and_refuses_odd_schema_names() { + let sql = probe_sql("acore_characters_wildcard").unwrap(); + assert!(sql.contains("table_schema = 'acore_characters_wildcard'")); + assert!(probe_sql("a'; DROP").is_err()); + } + + #[test] + fn probe_output_is_parsed_and_checked_against_the_registry() { + let out = "T\tcharacters\t\nT\tmod_new\t\nC\tmod_new\tguid\nC\tcharacters\tguid\nC\tmod_acct\taccount\n"; + let probe = parse_probe(out).unwrap(); + assert!(probe.has("characters") && probe.has("mod_new")); + assert_eq!(probe.unclassified_character_tables(), vec![("mod_new".to_string(), "guid".to_string())]); + assert!(probe.missing_required().contains(&"item_instance")); + assert!(parse_probe("X\ta\tb\n").is_err()); + assert!(parse_probe("T\ta\n").is_err()); + } + + #[test] + fn output_is_split_into_sections_by_marker() { + let probe = probe_with(&[]); + let qs: Vec = queries(1, &probe).unwrap().into_iter().filter(|q| matches!(q.name.as_str(), "spells" | "reputation")).collect(); + let out = "#T:spells\n10\t1\n11\t3\n#T:reputation\n"; + let raw = parse_output(out, &qs).unwrap(); + let spells: Vec<(u32, u8)> = raw.section("spells").unwrap().iter().map(|r| (r.u32("spell").unwrap(), r.u8("spec_mask").unwrap())).collect(); + assert_eq!(spells, vec![(10, 1), (11, 3)]); + assert!(raw.section("reputation").unwrap().is_empty()); + } + + #[test] + fn malformed_answers_are_refused() { + let qs: Vec = queries(1, &probe_with(&[])).unwrap().into_iter().filter(|q| q.name == "spells").collect(); + assert!(parse_output("#T:spells\n1\n", &qs).is_err(), "wrong column count"); + assert!(parse_output("#T:other\n", &qs).is_err(), "unknown section"); + assert!(parse_output("5\t1\n", &qs).is_err(), "data before a marker"); + assert!(parse_output("#T:spells\n#T:spells\n", &qs).is_err(), "twice"); + assert!(parse_output("", &qs).is_err(), "missing section"); + let raw = parse_output("#T:spells\nabc\t1\n", &qs).unwrap(); + assert!(raw.section("spells").unwrap().iter().next().unwrap().u32("spell").is_err()); + } + + #[test] + fn text_columns_are_hex_and_survive_any_content() { + let qs: Vec = queries(1, &probe_with(&[])).unwrap().into_iter().filter(|q| q.name == "settings").collect(); + let tricky = "tab\there \"quote\" 'q' back\\slash\nnewline NULL and \u{4e2d}\u{6587}"; + let out = format!("#T:settings\nx{}\tx{}\n", hex::encode(tricky), hex::encode("1 2 3 ")); + let raw = parse_output(&out, &qs).unwrap(); + let row = raw.section("settings").unwrap().iter().next().unwrap(); + assert_eq!(row.text("source").unwrap(), tricky); + assert_eq!(row.text("data").unwrap(), "1 2 3 "); + // SQL NULL and the 'no value' markers + let none = parse_output("#T:settings\nNULL\tN\n", &qs).unwrap(); + let row = none.section("settings").unwrap().iter().next().unwrap(); + assert_eq!((row.opt_text("source").unwrap(), row.opt_text("data").unwrap()), (None, None)); + let bad = parse_output("#T:settings\nxZZ\tx\n", &qs).unwrap(); + assert!(bad.section("settings").unwrap().iter().next().unwrap().text("source").is_err()); + } + + #[test] + fn the_list_query_hides_bots_and_is_read_only_too() { + let sql = list_sql(&probe_with(&["coa_character_gamemode"])); + assert!(sql.contains("COABOT%") && sql.contains("COAMANAGER")); + assert!(sql.contains("READ ONLY")); + assert!(sql.contains("gameMode <> 0")); + } +} diff --git a/crates/coa-core/src/portable/realm/testdata/characters-tables.txt b/crates/coa-core/src/portable/realm/testdata/characters-tables.txt new file mode 100644 index 0000000..ad5f8e3 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/characters-tables.txt @@ -0,0 +1,163 @@ +account_appearance_collection +account_ascension_settings +account_data +account_instance_times +account_tutorial +account_vanity_collection +active_arena_season +addons +arena_team +arena_team_member +ascension_manastorm_bonus +ascension_manastorm_cache +ascension_manastorm_clear +ascension_manastorm_loadout +ascension_manastorm_xp +ascension_player_ticket +ascension_player_ticket_message +auctionhouse +banned_addons +battleground_deserters +bugreport +calendar_events +calendar_invites +channels +channels_bans +channels_rights +character_account_data +character_achievement +character_achievement_offline_updates +character_achievement_progress +character_action +character_appearance +character_appearance_outfit +character_appearance_settings +character_arena_stats +character_ascension_state +character_aura +character_banned +character_battleground_random +character_brew_of_the_month +character_coa_lfg_settings +character_declinedname +character_entry_point +character_equipmentsets +character_gifts +character_glyphs +character_homebind +character_instance +character_inventory +character_pet +character_pet_declinedname +character_queststatus +character_queststatus_daily +character_queststatus_monthly +character_queststatus_rewarded +character_queststatus_seasonal +character_queststatus_weekly +character_reputation +character_settings +character_skills +character_social +character_spell +character_spell_cooldown +character_stats +character_talent +character_worldforged_loot +characters +chat_filter +coa_account_warchest +coa_bot_gear_history +coa_bot_gear_queue +coa_challenge_completion +coa_challenge_failure +coa_character_challenge +coa_character_condition +coa_character_fatigue +coa_character_gamemode +coa_character_gamemode_lives +coa_character_looted_item +coa_character_objective +coa_character_survival +coa_custom_trial +coa_custom_trial_active +coa_custom_trial_completion +coa_custom_trial_entry +coa_custom_trial_vote +coa_keepers_scroll_blessing +coa_squid_migrations +coa_wildcard_skill_card +coa_wildcard_skill_card_account +coa_wildcard_skill_card_pending +coa_wildcard_skill_card_purchase +coa_wildcard_specialization_cache +corpse +creature_respawn +ethereal_bazaar_meta +ethereal_bazaar_stock +game_event_condition_save +game_event_save +gameobject_respawn +gm_subsurvey +gm_survey +gm_ticket +group_member +groups +guild +guild_bank_eventlog +guild_bank_item +guild_bank_right +guild_bank_tab +guild_eventlog +guild_member +guild_member_withdraw +guild_rank +highrisk_chest +highrisk_chest_item +instance +instance_reset +instance_saved_go_state_data +item_instance +item_loot_storage +item_refund_instance +item_soulbound_trade_data +lag_reports +lfg_data +log_arena_fights +log_arena_memberstats +log_encounter +log_money +mail +mail_items +mail_server_character +mail_server_template +mail_server_template_conditions +mail_server_template_items +mod_ascension_bank_item +mod_ascension_bank_log +mod_ascension_bank_money +mod_ascension_bank_tab +mod_coa_bot_guild_gather_orders +mod_craftsmans_codex +pet_aura +pet_spell +pet_spell_cooldown +petition +petition_sign +player_anticheat_alert +playerbots_arena_team_names +playerbots_guild_names +playerbots_names +pool_quest_save +profanity_name +pvpstats_battlegrounds +pvpstats_players +quest_tracker +recovery_item +reserved_name +spam_reports +updates +updates_include +warden_action +world_state +worldstates diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1001.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1001.txt new file mode 100644 index 0000000..d174fb7 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1001.txt @@ -0,0 +1,28 @@ +#T:chars +1001 5001 x4E616B6564 1 12 0 1 0 0 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1002.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1002.txt new file mode 100644 index 0000000..ddca24a --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1002.txt @@ -0,0 +1,234 @@ +#T:chars +1002 5001 x476561726564 2 21 1 80 12345 200060523 1 2 3 4 0 4 1028 0 x3020302030203020 150 4092 10 20 777 3 4 5 165 72 1 0 x302037393139203135383338203233373537203331363736203339353935203437353134203535343333203633333532203731323731203739313930203837313039203935303238203239343420313038363320313837383220323637303120333436323020343235333920353034353820353833373720363632393620373432313520383231333420393030353320393739373220353838382031333830372032313732362032393634352033373536342034353438332035333430322036313332312036393234302037373135392038353037382039323939372039313320383833322031363735312032343637302033323538392034303530382034383432372035363334362036343236352037323138342038303130332038383032322039353934312033383537203131373736203139363935203237363134203335353333203433343532203531333731203539323930203637323039203735313238203833303437203930393636203938383835203638303120313437323020323236333920333035353820333834373720343633393620353433313520363232333420373031353320373830373220383539393120393339313020313832362039373435203137363634203235353833203333353032203431343231203439333430203537323539203635313738203733303937203831303136203838393335203936383534203437373020313236383920323036303820323835323720333634343620343433363520353232383420363032303320363831323220373630343120383339363020393138373920393937393820373731342031353633332032333535322033313437312033393339302034373330392035353232382036333134372037313036362037383938352038363930342039343832332032373339203130363538203138353737203236343936203334343135203432333334203530323533203538313732203636303931203734303130203831393239203839383438203937373637203536383320 x312030203020302030203020 15 2 100000 2 0 x504C4159455231 +#T:inventory +0 0 20001 +0 1 20002 +0 2 20003 +0 3 20004 +0 4 20005 +0 5 20006 +0 6 20007 +0 7 20008 +0 8 20009 +0 9 20010 +0 10 20011 +0 11 20012 +0 12 20013 +0 13 20014 +0 14 20015 +0 15 20016 +0 16 20017 +0 17 20018 +0 18 20019 +0 19 20020 +0 20 20021 +0 21 20022 +0 22 20023 +0 23 20048 +0 24 20049 +0 25 20050 +0 26 20051 +0 27 20052 +0 28 20053 +0 29 20054 +0 30 20055 +0 39 20056 +0 40 20057 +0 41 20058 +0 42 20060 +0 50 20999 +0 80 20062 +0 118 20059 +20020 0 20024 +20020 1 20025 +20020 2 20026 +20020 3 20027 +20020 4 20028 +20020 5 20029 +20021 0 20030 +20021 1 20031 +20021 2 20032 +20021 3 20033 +20021 4 20034 +20021 5 20035 +20022 0 20036 +20022 1 20037 +20022 2 20038 +20022 3 20039 +20022 4 20040 +20022 5 20041 +20023 0 20042 +20023 1 20043 +20023 2 20044 +20023 3 20045 +20023 4 20046 +20023 5 20047 +29999 3 29998 +#T:items +20001 30000 1 0 x30203020302030203020 1 x333030302030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 90 3600 N 0 - +20002 30017 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 91 3600 N 0 - +20003 30034 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 92 3600 N 0 - +20004 30051 1 0 x30203020302030203020 1 x333030332030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 93 3600 N 0 - +20005 30068 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 94 3600 N 1001 x4E616B6564 +20006 30085 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 -57 95 3600 N 0 - +20007 30102 1 0 x30203020302030203020 1 x333030362030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 96 3600 N 0 - +20008 30119 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 97 3600 N 0 - +20009 30136 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 98 3600 N 0 - +20010 30153 1 0 x30203020302030203020 1 x333030392030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 99 3600 N 0 - +20011 30170 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20012 30187 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 101 3600 N 0 - +20013 30204 1 0 x30203020302030203020 1 x333031322030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 102 3600 N 0 - +20014 30221 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 103 3600 N 0 - +20015 30238 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 104 3600 N 0 - +20016 30255 1 0 x30203020302030203020 1 x333031352030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 105 3600 N 0 - +20017 30272 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 106 3600 N 0 - +20018 30289 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 107 3600 N 0 - +20019 30306 1 0 x30203020302030203020 1 x333031382030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 108 3600 N 0 - +20020 41019 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20021 41020 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20022 41021 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20023 41022 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20024 50000 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20025 50001 5 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20026 50002 9 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20027 50003 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20028 50004 5 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20029 50005 9 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20030 50010 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20031 50011 5 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20032 50012 9 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20033 50013 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20034 50014 5 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20035 50015 9 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20036 50020 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20037 50021 5 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20038 50022 9 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20039 50023 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20040 50024 5 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20041 50025 9 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20042 50030 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20043 50031 5 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20044 50032 9 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20045 50033 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20046 50034 5 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20047 50035 9 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20048 60023 20 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20049 60024 20 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20050 60025 20 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20051 60026 20 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20052 60027 20 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20053 60028 20 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20054 60029 20 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20055 60030 20 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20056 70001 1 0 x30203020302030203020 1 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 x4120626F6F6B2E0A5365636F6E64206C696E6509776974682061207461622C2061202271756F7465222C20616E202761706F7374726F706865272C2061205C206261636B736C61736820616E6420E4B8ADE696872E 0 - +20057 70002 5 3600 x2D31203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20058 70003 1 0 N 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20059 375250 12 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20060 5042 1 0 x30203020302030203020 8 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +20062 70004 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 100 3600 N 0 - +29998 70099 1 0 x30203020302030203020 0 x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020 0 0 0 N 0 - +#T:gifts +20060 8000 8 +#T:spells +500003 1 +500006 1 +500009 1 +500012 1 +500015 3 +500018 1 +500021 1 +500024 1 +500027 1 +500030 3 +500033 1 +500036 1 +500039 1 +500042 1 +500045 3 +500048 1 +500051 1 +500054 1 +500057 1 +500060 3 +500063 1 +500066 1 +500069 1 +500072 1 +500075 3 +500078 1 +500081 1 +500084 1 +500087 1 +500090 3 +500093 1 +500096 1 +500099 1 +500102 1 +500105 3 +500108 1 +500111 1 +500114 1 +500117 1 +500120 3 +500123 1 +500126 1 +500129 1 +500132 1 +500135 3 +500138 1 +500141 1 +500144 1 +500147 1 +500150 3 +500153 1 +500156 1 +500159 1 +500162 1 +500165 3 +500168 1 +500171 1 +500174 1 +500177 1 +500180 3 +#T:talents +#T:skills +#T:glyphs +#T:reputation +3 -2900 1 +6 -2800 1 +9 -2700 1 +12 -2600 1 +15 -2500 1 +18 -2400 1 +21 -2300 17 +24 -2200 1 +27 -2100 1 +30 -2000 1 +33 -1900 1 +36 -1800 1 +39 -1700 1 +42 -1600 17 +45 -1500 1 +48 -1400 1 +51 -1300 1 +54 -1200 1 +57 -1100 1 +60 -1000 1 +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1003.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1003.txt new file mode 100644 index 0000000..05d80c1 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1003.txt @@ -0,0 +1,60 @@ +#T:chars +1003 5001 x517565737479 3 13 0 40 900 12345 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +1 50 1 +2 100 1 +3 150 1 +4 200 1 +5 250 1 +6 300 1 +7 350 1 +8 400 1 +9 450 1 +10 500 1 +#T:quests +12001 3 0 0 3 0 0 0 0 0 0 0 0 0 0 +12002 1 1 600 0 0 0 0 2 0 0 0 0 0 0 +#T:rewarded +12000 +12003 +12004 +#T:actions +0 0 500003 0 +0 1 500006 0 +0 2 500009 0 +0 3 500012 0 +0 4 500015 0 +0 5 500018 0 +0 6 500021 0 +0 7 500024 0 +0 8 500027 0 +0 9 500030 0 +0 10 500033 0 +0 11 500036 0 +1 0 500100 0 +1 1 500101 0 +1 2 500102 0 +1 3 500103 0 +1 4 7 64 +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1004.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1004.txt new file mode 100644 index 0000000..f19ced2 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1004.txt @@ -0,0 +1,356 @@ +#T:chars +1004 5001 xD094D180D0B0D0BAD0BED0BD 8 25 0 80 0 5000000 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +500003 2 +500006 3 +500009 1 +500012 2 +500015 3 +500018 1 +500021 2 +500024 3 +500027 1 +500030 2 +500033 3 +500036 1 +500039 2 +500042 3 +500045 1 +500048 2 +500051 3 +500054 1 +500057 2 +500060 3 +500063 1 +500066 2 +500069 3 +500072 1 +500075 2 +500078 3 +500081 1 +500084 2 +500087 3 +500090 1 +500093 2 +500096 3 +500099 1 +500102 2 +500105 3 +500108 1 +500111 2 +500114 3 +500117 1 +500120 2 +500123 3 +500126 1 +500129 2 +500132 3 +500135 1 +500138 2 +500141 3 +500144 1 +500147 2 +500150 3 +500153 1 +500156 2 +500159 3 +500162 1 +500165 2 +500168 3 +500171 1 +500174 2 +500177 3 +500180 1 +500183 2 +500186 3 +500189 1 +500192 2 +500195 3 +500198 1 +500201 2 +500204 3 +500207 1 +500210 2 +500213 3 +500216 1 +500219 2 +500222 3 +500225 1 +500228 2 +500231 3 +500234 1 +500237 2 +500240 3 +500243 1 +500246 2 +500249 3 +500252 1 +500255 2 +500258 3 +500261 1 +500264 2 +500267 3 +500270 1 +500273 2 +500276 3 +500279 1 +500282 2 +500285 3 +500288 1 +500291 2 +500294 3 +500297 1 +500300 2 +500303 3 +500306 1 +500309 2 +500312 3 +500315 1 +500318 2 +500321 3 +500324 1 +500327 2 +500330 3 +500333 1 +500336 2 +500339 3 +500342 1 +500345 2 +500348 3 +500351 1 +500354 2 +500357 3 +500360 1 +500363 2 +500366 3 +500369 1 +500372 2 +500375 3 +500378 1 +500381 2 +500384 3 +500387 1 +500390 2 +500393 3 +500396 1 +500399 2 +500402 3 +500405 1 +500408 2 +500411 3 +500414 1 +500417 2 +500420 3 +500423 1 +500426 2 +500429 3 +500432 1 +500435 2 +500438 3 +500441 1 +500444 2 +500447 3 +500450 1 +500453 2 +500456 3 +500459 1 +500462 2 +500465 3 +500468 1 +500471 2 +500474 3 +500477 1 +500480 2 +500483 3 +500486 1 +500489 2 +500492 3 +500495 1 +500498 2 +500501 3 +500504 1 +500507 2 +500510 3 +500513 1 +500516 2 +500519 3 +500522 1 +500525 2 +500528 3 +500531 1 +500534 2 +500537 3 +500540 1 +500543 2 +500546 3 +500549 1 +500552 2 +500555 3 +500558 1 +500561 2 +500564 3 +500567 1 +500570 2 +500573 3 +500576 1 +500579 2 +500582 3 +500585 1 +500588 2 +500591 3 +500594 1 +500597 2 +500600 3 +500603 1 +500606 2 +500609 3 +500612 1 +500615 2 +500618 3 +500621 1 +500624 2 +500627 3 +500630 1 +500633 2 +500636 3 +500639 1 +500642 2 +500645 3 +500648 1 +500651 2 +500654 3 +500657 1 +500660 2 +500663 3 +500666 1 +500669 2 +500672 3 +500675 1 +500678 2 +500681 3 +500684 1 +500687 2 +500690 3 +500693 1 +500696 2 +500699 3 +500702 1 +500705 2 +500708 3 +500711 1 +500714 2 +500717 3 +500720 1 +500723 2 +500726 3 +500729 1 +500732 2 +500735 3 +500738 1 +500741 2 +500744 3 +500747 1 +500750 2 +500753 3 +500756 1 +500759 2 +500762 3 +500765 1 +500768 2 +500771 3 +500774 1 +500777 2 +500780 3 +500783 1 +500786 2 +500789 3 +500792 1 +500795 2 +500798 3 +500801 1 +500804 2 +500807 3 +500810 1 +500813 2 +500816 3 +500819 1 +500822 2 +500825 3 +500828 1 +500831 2 +500834 3 +500837 1 +500840 2 +500843 3 +500846 1 +500849 2 +500852 3 +500855 1 +500858 2 +500861 3 +500864 1 +500867 2 +500870 3 +500873 1 +500876 2 +500879 3 +500882 1 +500885 2 +500888 3 +500891 1 +500894 2 +500897 3 +500900 1 +#T:talents +900001 1 +900002 1 +900003 1 +900004 1 +900005 1 +#T:skills +100 300 450 +101 301 450 +102 302 450 +103 303 450 +104 304 450 +105 305 450 +106 306 450 +107 307 450 +108 308 450 +109 309 450 +#T:glyphs +0 1 2 3 4 5 6 +1 7 0 0 0 0 0 +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +x636F612E626F742E67656172 x312032203320 +x636F612E676561725F707265665F776561706F6E x3220 +x636F72652E617363656E73696F6E5F6163746976655F73706563 x353420 +x636F72652E617363656E73696F6E5F6261722E3534 x3220302035303030303320312035303030303620 +x636F72652E617363656E73696F6E5F6275696C642E3534 x3320353637313020353633323020393031303120 +x636F72652E617363656E73696F6E5F736C6F742E616374697665 x3020 +x636F72652E617363656E73696F6E5F73746172746572 x3120 +x636F72652E7370656C6C5F6368617267652E383034313937 x32203137393030303030303020 +x636F72652E77696C64636172642E6361726473 x31203220 +x6D6F642E6578616D706C652E6E65775F66656174757265 x392038203720 +#T:macros +1790000000 xFD2992936477103705783B2983ECDABC6F022B53FF446C4155EA1E0E31DF205D8B3FC6F87451B67413FD007D6B323F14D2FE5614DAB33BA9139D96F75EFE4E174239ED1136FC75F79A48242521E33AEE5A6F823526D45D0BCE04EA37BE3AF121DD56A5FB7426D3F9E8B71B94D4206BE32D2ACF91F3DD3AE245F707FD03E94EE0DAB632509D06D513DC0F8890EA7C3948CC225BDCBB0C8AF86CD220B053D96EDAF1447490F93185D89F27D586C80F528A4A487656EF877AF17D72DBC23E00ED38E64E2AA1CB0016697726654CBAE0465CCC0004677C123BC01ED87E7238E14295CDBBBF62DE4B7FAEDC776E0E9C0D6A047568D3719575223E440FAA36F1C5EF21FF2EFD915A8B3AB8234101E50332C8379D4E27FC28857EC526B00C50CBE696AE954521913EA5066031762940E310A5A4277DDAABB670AFCC984E06B3C55F3E0BEAD7E755F14A3E9FE98C46E9A32B2640668918AB1097C40FA5471006036F036469813F251E49C242543C82523BAB6E3CC5F165786319C50034233D86B4ADBB9CC7E105754FFF50808B70322090CCF883C207B250E0388124AA04FD08124D1F5F720DE546CA8E73DDC9E71BB1C5A0DF67B65CCC8AFCEDE46054CFD44B452B322D76B54CB041D9BB49F0CCC5EA584C30CD67BFE1DC599924483F019E05500EB6584A2F7AFCF838555047C3C901C74DD155E9EC10D3EFDB7A63CED430E92B6478676B56BDB7C204D131962AA83F14C7490D31847CAD304928DD3BF148BAE93DD0D82D1A361A455F6CAA3DBD1705F0281CFFF36CA6488F367560221D2C1BF44DBF05A48B9AB810F4A870E5E64A53181AAD6AB9AC484363468D130001FF20656E64 +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1005.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1005.txt new file mode 100644 index 0000000..0ef2c99 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1005.txt @@ -0,0 +1,39 @@ +#T:chars +1005 5001 x48756E7479 4 14 0 60 0 0 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 2 0 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +3001 42 901 1515 1 60 1000 1 x526578 0 0 5000 100 1000000 x372032203020302031203020312031203020 +3002 43 902 1515 1 55 200 1 x46616E67 1 1 4000 90 900000 x37203220 +3003 416 4449 688 0 60 0 1 x496D70 0 100 3000 400 0 N +#T:pet_spells +3001 16827 0 +3001 17253 1 +3001 24604 1 +3001 34889 1 +3001 50256 0 +3001 61683 0 +3003 3110 1 +#T:pet_declined +3002 xD0A4D0B0D0BDD0B3D0B0 xD0A4D0B0D0BDD0B3D183 xD0A4D0B0D0BDD0B3 xD0A4D0B0D0BDD0B3D0BED0BC xD0A4D0B0D0BDD0B3D0B5 +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1006.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1006.txt new file mode 100644 index 0000000..7887802 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1006.txt @@ -0,0 +1,28 @@ +#T:chars +1006 5001 x4F6E6C696E65 1 12 0 10 0 0 1 2 3 4 0 0 0 1 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1007.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1007.txt new file mode 100644 index 0000000..103e2be --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1007.txt @@ -0,0 +1,28 @@ +#T:chars +1007 5001 x48617264636F7265 1 12 0 10 0 0 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +1 +#T:block:gamemode +1 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1008.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1008.txt new file mode 100644 index 0000000..e89253e --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1008.txt @@ -0,0 +1,28 @@ +#T:chars +1008 5001 x436163686579 1 12 0 30 0 0 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +1 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1009.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1009.txt new file mode 100644 index 0000000..797be41 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1009.txt @@ -0,0 +1,28 @@ +#T:chars +1009 5001 x44656C65746564 1 12 0 20 0 0 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 1 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1010.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1010.txt new file mode 100644 index 0000000..f247c6c --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1010.txt @@ -0,0 +1,28 @@ +#T:chars +1010 5002 x426F747479 1 12 0 80 0 0 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x434F41424F54484F535431 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1011.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1011.txt new file mode 100644 index 0000000..8ecdabf --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1011.txt @@ -0,0 +1,28 @@ +#T:chars +1011 5003 x4D6F646479 1 12 0 50 0 0 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x504C4159455233 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +1 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/export-1012.txt b/crates/coa-core/src/portable/realm/testdata/golden/export-1012.txt new file mode 100644 index 0000000..6e69c42 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/export-1012.txt @@ -0,0 +1,28 @@ +#T:chars +1012 5001 x486973746F7279 1 12 0 60 0 0 1 2 3 4 0 0 0 0 x3020302030203020 0 0 0 0 0 0 0 0 0 0 1 0 x3020302030203020 x302030203020302030203020 0 0 0 0 0 x504C4159455231 +#T:inventory +#T:items +#T:gifts +#T:spells +#T:talents +#T:skills +#T:glyphs +#T:reputation +#T:quests +#T:rewarded +#T:actions +#T:pets +#T:pet_spells +#T:pet_declined +#T:settings +#T:macros +#T:block:challenge +0 +#T:block:gamemode +0 +#T:block:trial +0 +#T:block:manastorm +0 +#T:unclassified:mod_unknown_state +0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/list.txt b/crates/coa-core/src/portable/realm/testdata/golden/list.txt new file mode 100644 index 0000000..7486b21 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/list.txt @@ -0,0 +1,11 @@ +1001 x4E616B6564 1 12 1 0 5001 x504C4159455231 0 0 0 0 0 +1002 x476561726564 2 21 80 0 5001 x504C4159455231 0 0 0 0 0 +1003 x517565737479 3 13 40 0 5001 x504C4159455231 0 0 0 0 0 +1004 xD094D180D0B0D0BAD0BED0BD 8 25 80 0 5001 x504C4159455231 0 0 0 0 0 +1005 x48756E7479 4 14 60 0 5001 x504C4159455231 0 0 0 0 0 +1006 x4F6E6C696E65 1 12 10 1 5001 x504C4159455231 0 0 0 0 0 +1007 x48617264636F7265 1 12 10 0 5001 x504C4159455231 0 1 1 0 0 +1008 x436163686579 1 12 30 0 5001 x504C4159455231 0 0 0 0 1 +1009 x44656C65746564 1 12 20 0 5001 x504C4159455231 1 0 0 0 0 +1011 x4D6F646479 1 12 50 0 5003 x504C4159455233 0 0 0 0 0 +1012 x486973746F7279 1 12 60 0 5001 x504C4159455231 0 0 0 0 0 diff --git a/crates/coa-core/src/portable/realm/testdata/golden/probe.txt b/crates/coa-core/src/portable/realm/testdata/golden/probe.txt new file mode 100644 index 0000000..30875f2 --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/golden/probe.txt @@ -0,0 +1,265 @@ +C arena_team_member guid +C ascension_manastorm_bonus guid +C ascension_manastorm_cache guid +C ascension_manastorm_clear guid +C ascension_manastorm_loadout guid +C ascension_manastorm_xp guid +C battleground_deserters guid +C channels_bans playerGUID +C character_account_data guid +C character_achievement guid +C character_achievement_offline_updates guid +C character_achievement_progress guid +C character_action guid +C character_appearance guid +C character_appearance_outfit guid +C character_appearance_settings guid +C character_arena_stats guid +C character_ascension_state guid +C character_aura guid +C character_banned guid +C character_battleground_random guid +C character_brew_of_the_month guid +C character_coa_lfg_settings guid +C character_declinedname guid +C character_entry_point guid +C character_equipmentsets guid +C character_gifts guid +C character_glyphs guid +C character_homebind guid +C character_instance guid +C character_inventory guid +C character_pet owner +C character_pet_declinedname owner +C character_queststatus guid +C character_queststatus_daily guid +C character_queststatus_monthly guid +C character_queststatus_rewarded guid +C character_queststatus_seasonal guid +C character_queststatus_weekly guid +C character_reputation guid +C character_settings guid +C character_skills guid +C character_social guid +C character_spell guid +C character_spell_cooldown guid +C character_stats guid +C character_talent guid +C character_worldforged_loot guid +C characters guid +C coa_bot_gear_history guid +C coa_bot_gear_queue guid +C coa_challenge_completion guid +C coa_challenge_failure guid +C coa_character_challenge guid +C coa_character_condition guid +C coa_character_fatigue guid +C coa_character_gamemode guid +C coa_character_gamemode_lives guid +C coa_character_looted_item guid +C coa_character_objective guid +C coa_character_survival guid +C coa_custom_trial guid +C coa_custom_trial_active guid +C coa_custom_trial_completion guid +C coa_custom_trial_entry guid +C coa_custom_trial_vote guid +C corpse guid +C creature_respawn guid +C gameobject_respawn guid +C gm_survey guid +C gm_ticket playerGuid +C group_member guid +C groups guid +C guild_bank_eventlog PlayerGuid +C guild_member guid +C guild_member_withdraw guid +C highrisk_chest owner +C instance_saved_go_state_data guid +C item_instance guid +C item_instance owner_guid +C item_refund_instance player_guid +C lag_reports guid +C lfg_data guid +C log_arena_memberstats guid +C mail_server_character guid +C mod_ascension_bank_item owner_id +C mod_ascension_bank_log owner_id +C mod_ascension_bank_log player_guid +C mod_ascension_bank_money owner_id +C mod_ascension_bank_tab owner_id +C mod_coa_bot_guild_gather_orders bot_guid +C mod_craftsmans_codex guid +C mod_unknown_state guid +C pet_aura guid +C pet_spell guid +C pet_spell_cooldown guid +C petition_sign playerguid +C player_anticheat_alert guid +C pvpstats_players character_guid +C quest_tracker character_guid +C recovery_item Guid +T account_appearance_collection - +T account_ascension_settings - +T account_data - +T account_instance_times - +T account_tutorial - +T account_vanity_collection - +T active_arena_season - +T addons - +T arena_team - +T arena_team_member - +T ascension_manastorm_bonus - +T ascension_manastorm_cache - +T ascension_manastorm_clear - +T ascension_manastorm_loadout - +T ascension_manastorm_xp - +T ascension_player_ticket - +T ascension_player_ticket_message - +T auctionhouse - +T banned_addons - +T battleground_deserters - +T bugreport - +T calendar_events - +T calendar_invites - +T channels - +T channels_bans - +T channels_rights - +T character_account_data - +T character_achievement - +T character_achievement_offline_updates - +T character_achievement_progress - +T character_action - +T character_appearance - +T character_appearance_outfit - +T character_appearance_settings - +T character_arena_stats - +T character_ascension_state - +T character_aura - +T character_banned - +T character_battleground_random - +T character_brew_of_the_month - +T character_coa_lfg_settings - +T character_declinedname - +T character_entry_point - +T character_equipmentsets - +T character_gifts - +T character_glyphs - +T character_homebind - +T character_instance - +T character_inventory - +T character_pet - +T character_pet_declinedname - +T character_queststatus - +T character_queststatus_daily - +T character_queststatus_monthly - +T character_queststatus_rewarded - +T character_queststatus_seasonal - +T character_queststatus_weekly - +T character_reputation - +T character_settings - +T character_skills - +T character_social - +T character_spell - +T character_spell_cooldown - +T character_stats - +T character_talent - +T character_worldforged_loot - +T characters - +T chat_filter - +T coa_account_warchest - +T coa_bot_gear_history - +T coa_bot_gear_queue - +T coa_challenge_completion - +T coa_challenge_failure - +T coa_character_challenge - +T coa_character_condition - +T coa_character_fatigue - +T coa_character_gamemode - +T coa_character_gamemode_lives - +T coa_character_looted_item - +T coa_character_objective - +T coa_character_survival - +T coa_custom_trial - +T coa_custom_trial_active - +T coa_custom_trial_completion - +T coa_custom_trial_entry - +T coa_custom_trial_vote - +T coa_keepers_scroll_blessing - +T coa_squid_migrations - +T coa_wildcard_skill_card - +T coa_wildcard_skill_card_account - +T coa_wildcard_skill_card_pending - +T coa_wildcard_skill_card_purchase - +T coa_wildcard_specialization_cache - +T corpse - +T creature_respawn - +T ethereal_bazaar_meta - +T ethereal_bazaar_stock - +T game_event_condition_save - +T game_event_save - +T gameobject_respawn - +T gm_subsurvey - +T gm_survey - +T gm_ticket - +T group_member - +T groups - +T guild - +T guild_bank_eventlog - +T guild_bank_item - +T guild_bank_right - +T guild_bank_tab - +T guild_eventlog - +T guild_member - +T guild_member_withdraw - +T guild_rank - +T highrisk_chest - +T highrisk_chest_item - +T instance - +T instance_reset - +T instance_saved_go_state_data - +T item_instance - +T item_loot_storage - +T item_refund_instance - +T item_soulbound_trade_data - +T lag_reports - +T lfg_data - +T log_arena_fights - +T log_arena_memberstats - +T log_encounter - +T log_money - +T mail - +T mail_items - +T mail_server_character - +T mail_server_template - +T mail_server_template_conditions - +T mail_server_template_items - +T mod_ascension_bank_item - +T mod_ascension_bank_log - +T mod_ascension_bank_money - +T mod_ascension_bank_tab - +T mod_coa_bot_guild_gather_orders - +T mod_craftsmans_codex - +T mod_unknown_state - +T pet_aura - +T pet_spell - +T pet_spell_cooldown - +T petition - +T petition_sign - +T player_anticheat_alert - +T playerbots_arena_team_names - +T playerbots_guild_names - +T playerbots_names - +T pool_quest_save - +T profanity_name - +T pvpstats_battlegrounds - +T pvpstats_players - +T quest_tracker - +T recovery_item - +T reserved_name - +T spam_reports - +T updates - +T updates_include - +T warden_action - +T world_state - +T worldstates - diff --git a/crates/coa-core/src/portable/realm/testdata/realm-fixture.sql b/crates/coa-core/src/portable/realm/testdata/realm-fixture.sql new file mode 100644 index 0000000..4f1f3bc --- /dev/null +++ b/crates/coa-core/src/portable/realm/testdata/realm-fixture.sql @@ -0,0 +1,640 @@ +-- generated by tools/gen_portable_fixture.py; applied to a disposable, empty characters + auth schema only +INSERT INTO acore_auth.account (id, username, salt, verifier) VALUES (5001, 'PLAYER1', UNHEX(REPEAT('11',32)), UNHEX(REPEAT('22',32))); +INSERT INTO acore_auth.account (id, username, salt, verifier) VALUES (5002, 'COABOTHOST1', UNHEX(REPEAT('11',32)), UNHEX(REPEAT('22',32))); +INSERT INTO acore_auth.account (id, username, salt, verifier) VALUES (5003, 'PLAYER3', UNHEX(REPEAT('11',32)), UNHEX(REPEAT('22',32))); +CREATE TABLE IF NOT EXISTS acore_characters.mod_unknown_state (guid INT UNSIGNED NOT NULL, note VARCHAR(32) NOT NULL, PRIMARY KEY (guid)); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1001, 5001, _utf8mb4 0x4e616b6564, 1, 12, 0, 1, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1002, 5001, _utf8mb4 0x476561726564, 2, 21, 1, 80, 12345, 200060523, 1, 2, 3, 4, 0, 4, 1028, _utf8mb4 0x3020302030203020, 0, 150, 4092, 10, 20, 777, 3, 4, 5, 165, 72, 1, 0, _utf8mb4 0x302037393139203135383338203233373537203331363736203339353935203437353134203535343333203633333532203731323731203739313930203837313039203935303238203239343420313038363320313837383220323637303120333436323020343235333920353034353820353833373720363632393620373432313520383231333420393030353320393739373220353838382031333830372032313732362032393634352033373536342034353438332035333430322036313332312036393234302037373135392038353037382039323939372039313320383833322031363735312032343637302033323538392034303530382034383432372035363334362036343236352037323138342038303130332038383032322039353934312033383537203131373736203139363935203237363134203335353333203433343532203531333731203539323930203637323039203735313238203833303437203930393636203938383835203638303120313437323020323236333920333035353820333834373720343633393620353433313520363232333420373031353320373830373220383539393120393339313020313832362039373435203137363634203235353833203333353032203431343231203439333430203537323539203635313738203733303937203831303136203838393335203936383534203437373020313236383920323036303820323835323720333634343620343433363520353232383420363032303320363831323220373630343120383339363020393138373920393937393820373731342031353633332032333535322033313437312033393339302034373330392035353232382036333134372037313036362037383938352038363930342039343832332032373339203130363538203138353737203236343936203334343135203432333334203530323533203538313732203636303931203734303130203831393239203839383438203937373637203536383320, _utf8mb4 0x312030203020302030203020, 15, 2, 100000, 2, 0, NULL); +INSERT INTO acore_characters.`item_instance` (`guid`, `itemEntry`, `owner_guid`, `creatorGuid`, `giftCreatorGuid`, `count`, `duration`, `charges`, `flags`, `enchantments`, `randomPropertyId`, `durability`, `playedTime`, `text`) VALUES + (20001, 30000, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x333030302030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 90, 3600, NULL), + (20002, 30017, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 91, 3600, NULL), + (20003, 30034, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 92, 3600, NULL), + (20004, 30051, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x333030332030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 93, 3600, NULL), + (20005, 30068, 1002, 1001, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 94, 3600, NULL), + (20006, 30085, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, -57, 95, 3600, NULL), + (20007, 30102, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x333030362030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 96, 3600, NULL), + (20008, 30119, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 97, 3600, NULL), + (20009, 30136, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 98, 3600, NULL), + (20010, 30153, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x333030392030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 99, 3600, NULL), + (20011, 30170, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20012, 30187, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 101, 3600, NULL), + (20013, 30204, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x333031322030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 102, 3600, NULL), + (20014, 30221, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 103, 3600, NULL), + (20015, 30238, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 104, 3600, NULL), + (20016, 30255, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x333031352030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 105, 3600, NULL), + (20017, 30272, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 106, 3600, NULL), + (20018, 30289, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 107, 3600, NULL), + (20019, 30306, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x333031382030203020302030203020333837382030203020333837392030203020333838302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 108, 3600, NULL), + (20020, 41019, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20021, 41020, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20022, 41021, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20023, 41022, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20024, 50000, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20025, 50001, 1002, 0, 0, 5, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20026, 50002, 1002, 0, 0, 9, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20027, 50003, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20028, 50004, 1002, 0, 0, 5, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20029, 50005, 1002, 0, 0, 9, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20030, 50010, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20031, 50011, 1002, 0, 0, 5, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20032, 50012, 1002, 0, 0, 9, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20033, 50013, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20034, 50014, 1002, 0, 0, 5, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20035, 50015, 1002, 0, 0, 9, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20036, 50020, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20037, 50021, 1002, 0, 0, 5, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20038, 50022, 1002, 0, 0, 9, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20039, 50023, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20040, 50024, 1002, 0, 0, 5, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20041, 50025, 1002, 0, 0, 9, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20042, 50030, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20043, 50031, 1002, 0, 0, 5, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20044, 50032, 1002, 0, 0, 9, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20045, 50033, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20046, 50034, 1002, 0, 0, 5, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20047, 50035, 1002, 0, 0, 9, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20048, 60023, 1002, 0, 0, 20, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20049, 60024, 1002, 0, 0, 20, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20050, 60025, 1002, 0, 0, 20, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20051, 60026, 1002, 0, 0, 20, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20052, 60027, 1002, 0, 0, 20, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20053, 60028, 1002, 0, 0, 20, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20054, 60029, 1002, 0, 0, 20, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20055, 60030, 1002, 0, 0, 20, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20056, 70001, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 1, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, _utf8mb4 0x4120626f6f6b2e0a5365636f6e64206c696e6509776974682061207461622c2061202271756f7465222c20616e202761706f7374726f706865272c2061205c206261636b736c61736820616e6420e4b8ade696872e), + (20057, 70002, 1002, 0, 0, 5, 3600, _utf8mb4 0x2d31203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20058, 70003, 1002, 0, 0, 1, 0, NULL, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20059, 375250, 1002, 0, 0, 12, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (20060, 5042, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 8, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL), + (29998, 70099, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 0, 0, NULL), + (20062, 70004, 1002, 0, 0, 1, 0, _utf8mb4 0x30203020302030203020, 0, _utf8mb4 0x302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020302030203020, 0, 100, 3600, NULL); +INSERT INTO acore_characters.`character_inventory` (`guid`, `bag`, `slot`, `item`) VALUES + (1002, 0, 0, 20001), + (1002, 0, 1, 20002), + (1002, 0, 2, 20003), + (1002, 0, 3, 20004), + (1002, 0, 4, 20005), + (1002, 0, 5, 20006), + (1002, 0, 6, 20007), + (1002, 0, 7, 20008), + (1002, 0, 8, 20009), + (1002, 0, 9, 20010), + (1002, 0, 10, 20011), + (1002, 0, 11, 20012), + (1002, 0, 12, 20013), + (1002, 0, 13, 20014), + (1002, 0, 14, 20015), + (1002, 0, 15, 20016), + (1002, 0, 16, 20017), + (1002, 0, 17, 20018), + (1002, 0, 18, 20019), + (1002, 0, 19, 20020), + (1002, 0, 20, 20021), + (1002, 0, 21, 20022), + (1002, 0, 22, 20023), + (1002, 20020, 0, 20024), + (1002, 20020, 1, 20025), + (1002, 20020, 2, 20026), + (1002, 20020, 3, 20027), + (1002, 20020, 4, 20028), + (1002, 20020, 5, 20029), + (1002, 20021, 0, 20030), + (1002, 20021, 1, 20031), + (1002, 20021, 2, 20032), + (1002, 20021, 3, 20033), + (1002, 20021, 4, 20034), + (1002, 20021, 5, 20035), + (1002, 20022, 0, 20036), + (1002, 20022, 1, 20037), + (1002, 20022, 2, 20038), + (1002, 20022, 3, 20039), + (1002, 20022, 4, 20040), + (1002, 20022, 5, 20041), + (1002, 20023, 0, 20042), + (1002, 20023, 1, 20043), + (1002, 20023, 2, 20044), + (1002, 20023, 3, 20045), + (1002, 20023, 4, 20046), + (1002, 20023, 5, 20047), + (1002, 0, 23, 20048), + (1002, 0, 24, 20049), + (1002, 0, 25, 20050), + (1002, 0, 26, 20051), + (1002, 0, 27, 20052), + (1002, 0, 28, 20053), + (1002, 0, 29, 20054), + (1002, 0, 30, 20055), + (1002, 0, 39, 20056), + (1002, 0, 40, 20057), + (1002, 0, 41, 20058), + (1002, 0, 118, 20059), + (1002, 0, 42, 20060), + (1002, 0, 50, 20999), + (1002, 29999, 3, 29998), + (1002, 0, 80, 20062); +INSERT INTO acore_characters.`character_gifts` (`guid`, `item_guid`, `entry`, `flags`) VALUES + (1002, 20060, 8000, 8); +INSERT INTO acore_characters.`character_spell` (`guid`, `spell`, `specMask`) VALUES + (1002, 500003, 1), + (1002, 500006, 1), + (1002, 500009, 1), + (1002, 500012, 1), + (1002, 500015, 3), + (1002, 500018, 1), + (1002, 500021, 1), + (1002, 500024, 1), + (1002, 500027, 1), + (1002, 500030, 3), + (1002, 500033, 1), + (1002, 500036, 1), + (1002, 500039, 1), + (1002, 500042, 1), + (1002, 500045, 3), + (1002, 500048, 1), + (1002, 500051, 1), + (1002, 500054, 1), + (1002, 500057, 1), + (1002, 500060, 3), + (1002, 500063, 1), + (1002, 500066, 1), + (1002, 500069, 1), + (1002, 500072, 1), + (1002, 500075, 3), + (1002, 500078, 1), + (1002, 500081, 1), + (1002, 500084, 1), + (1002, 500087, 1), + (1002, 500090, 3), + (1002, 500093, 1), + (1002, 500096, 1), + (1002, 500099, 1), + (1002, 500102, 1), + (1002, 500105, 3), + (1002, 500108, 1), + (1002, 500111, 1), + (1002, 500114, 1), + (1002, 500117, 1), + (1002, 500120, 3), + (1002, 500123, 1), + (1002, 500126, 1), + (1002, 500129, 1), + (1002, 500132, 1), + (1002, 500135, 3), + (1002, 500138, 1), + (1002, 500141, 1), + (1002, 500144, 1), + (1002, 500147, 1), + (1002, 500150, 3), + (1002, 500153, 1), + (1002, 500156, 1), + (1002, 500159, 1), + (1002, 500162, 1), + (1002, 500165, 3), + (1002, 500168, 1), + (1002, 500171, 1), + (1002, 500174, 1), + (1002, 500177, 1), + (1002, 500180, 3); +INSERT INTO acore_characters.`character_reputation` (`guid`, `faction`, `standing`, `flags`) VALUES + (1002, 3, -2900, 1), + (1002, 6, -2800, 1), + (1002, 9, -2700, 1), + (1002, 12, -2600, 1), + (1002, 15, -2500, 1), + (1002, 18, -2400, 1), + (1002, 21, -2300, 17), + (1002, 24, -2200, 1), + (1002, 27, -2100, 1), + (1002, 30, -2000, 1), + (1002, 33, -1900, 1), + (1002, 36, -1800, 1), + (1002, 39, -1700, 1), + (1002, 42, -1600, 17), + (1002, 45, -1500, 1), + (1002, 48, -1400, 1), + (1002, 51, -1300, 1), + (1002, 54, -1200, 1), + (1002, 57, -1100, 1), + (1002, 60, -1000, 1); +INSERT INTO acore_characters.character_homebind (guid, mapId, zoneId, posX, posY, posZ) VALUES (1002, 0, 12, 1.5, 2.5, 3.5); +INSERT INTO acore_characters.character_aura (guid, casterGuid, itemGuid, spell, effectMask, recalculateMask, stackCount, maxDuration, remainTime, remainCharges) VALUES (1002, 1002, 0, 12345, 1, 0, 1, 60000, 30000, 0); +INSERT INTO acore_characters.character_spell_cooldown (guid, spell, category, item, time, needSend) VALUES (1002, 500003, 0, 0, 1790000000, 0); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1003, 5001, _utf8mb4 0x517565737479, 3, 13, 0, 40, 900, 12345, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.`character_queststatus` (`guid`, `quest`, `status`, `explored`, `timer`, `mobcount1`, `mobcount2`, `mobcount3`, `mobcount4`, `itemcount1`, `itemcount2`, `itemcount3`, `itemcount4`, `itemcount5`, `itemcount6`, `playercount`) VALUES + (1003, 12001, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), + (1003, 12002, 1, 1, 600, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0); +INSERT INTO acore_characters.`character_queststatus_rewarded` (`guid`, `quest`, `active`) VALUES + (1003, 12000, 1), + (1003, 12003, 1), + (1003, 12004, 1), + (1003, 12005, 0); +INSERT INTO acore_characters.`character_queststatus_daily` (`guid`, `quest`, `time`) VALUES + (1003, 13000, 1790000000); +INSERT INTO acore_characters.`character_reputation` (`guid`, `faction`, `standing`, `flags`) VALUES + (1003, 1, 50, 1), + (1003, 2, 100, 1), + (1003, 3, 150, 1), + (1003, 4, 200, 1), + (1003, 5, 250, 1), + (1003, 6, 300, 1), + (1003, 7, 350, 1), + (1003, 8, 400, 1), + (1003, 9, 450, 1), + (1003, 10, 500, 1); +INSERT INTO acore_characters.`character_action` (`guid`, `spec`, `button`, `action`, `type`) VALUES + (1003, 0, 0, 500003, 0), + (1003, 0, 1, 500006, 0), + (1003, 0, 2, 500009, 0), + (1003, 0, 3, 500012, 0), + (1003, 0, 4, 500015, 0), + (1003, 0, 5, 500018, 0), + (1003, 0, 6, 500021, 0), + (1003, 0, 7, 500024, 0), + (1003, 0, 8, 500027, 0), + (1003, 0, 9, 500030, 0), + (1003, 0, 10, 500033, 0), + (1003, 0, 11, 500036, 0), + (1003, 1, 0, 500100, 0), + (1003, 1, 1, 500101, 0), + (1003, 1, 2, 500102, 0), + (1003, 1, 3, 500103, 0), + (1003, 1, 4, 7, 64); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1004, 5001, _utf8mb4 0xd094d180d0b0d0bad0bed0bd, 8, 25, 0, 80, 0, 5000000, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.`character_spell` (`guid`, `spell`, `specMask`) VALUES + (1004, 500003, 2), + (1004, 500006, 3), + (1004, 500009, 1), + (1004, 500012, 2), + (1004, 500015, 3), + (1004, 500018, 1), + (1004, 500021, 2), + (1004, 500024, 3), + (1004, 500027, 1), + (1004, 500030, 2), + (1004, 500033, 3), + (1004, 500036, 1), + (1004, 500039, 2), + (1004, 500042, 3), + (1004, 500045, 1), + (1004, 500048, 2), + (1004, 500051, 3), + (1004, 500054, 1), + (1004, 500057, 2), + (1004, 500060, 3), + (1004, 500063, 1), + (1004, 500066, 2), + (1004, 500069, 3), + (1004, 500072, 1), + (1004, 500075, 2), + (1004, 500078, 3), + (1004, 500081, 1), + (1004, 500084, 2), + (1004, 500087, 3), + (1004, 500090, 1), + (1004, 500093, 2), + (1004, 500096, 3), + (1004, 500099, 1), + (1004, 500102, 2), + (1004, 500105, 3), + (1004, 500108, 1), + (1004, 500111, 2), + (1004, 500114, 3), + (1004, 500117, 1), + (1004, 500120, 2), + (1004, 500123, 3), + (1004, 500126, 1), + (1004, 500129, 2), + (1004, 500132, 3), + (1004, 500135, 1), + (1004, 500138, 2), + (1004, 500141, 3), + (1004, 500144, 1), + (1004, 500147, 2), + (1004, 500150, 3), + (1004, 500153, 1), + (1004, 500156, 2), + (1004, 500159, 3), + (1004, 500162, 1), + (1004, 500165, 2), + (1004, 500168, 3), + (1004, 500171, 1), + (1004, 500174, 2), + (1004, 500177, 3), + (1004, 500180, 1), + (1004, 500183, 2), + (1004, 500186, 3), + (1004, 500189, 1), + (1004, 500192, 2), + (1004, 500195, 3), + (1004, 500198, 1), + (1004, 500201, 2), + (1004, 500204, 3), + (1004, 500207, 1), + (1004, 500210, 2), + (1004, 500213, 3), + (1004, 500216, 1), + (1004, 500219, 2), + (1004, 500222, 3), + (1004, 500225, 1), + (1004, 500228, 2), + (1004, 500231, 3), + (1004, 500234, 1), + (1004, 500237, 2), + (1004, 500240, 3), + (1004, 500243, 1), + (1004, 500246, 2), + (1004, 500249, 3), + (1004, 500252, 1), + (1004, 500255, 2), + (1004, 500258, 3), + (1004, 500261, 1), + (1004, 500264, 2), + (1004, 500267, 3), + (1004, 500270, 1), + (1004, 500273, 2), + (1004, 500276, 3), + (1004, 500279, 1), + (1004, 500282, 2), + (1004, 500285, 3), + (1004, 500288, 1), + (1004, 500291, 2), + (1004, 500294, 3), + (1004, 500297, 1), + (1004, 500300, 2), + (1004, 500303, 3), + (1004, 500306, 1), + (1004, 500309, 2), + (1004, 500312, 3), + (1004, 500315, 1), + (1004, 500318, 2), + (1004, 500321, 3), + (1004, 500324, 1), + (1004, 500327, 2), + (1004, 500330, 3), + (1004, 500333, 1), + (1004, 500336, 2), + (1004, 500339, 3), + (1004, 500342, 1), + (1004, 500345, 2), + (1004, 500348, 3), + (1004, 500351, 1), + (1004, 500354, 2), + (1004, 500357, 3), + (1004, 500360, 1), + (1004, 500363, 2), + (1004, 500366, 3), + (1004, 500369, 1), + (1004, 500372, 2), + (1004, 500375, 3), + (1004, 500378, 1), + (1004, 500381, 2), + (1004, 500384, 3), + (1004, 500387, 1), + (1004, 500390, 2), + (1004, 500393, 3), + (1004, 500396, 1), + (1004, 500399, 2), + (1004, 500402, 3), + (1004, 500405, 1), + (1004, 500408, 2), + (1004, 500411, 3), + (1004, 500414, 1), + (1004, 500417, 2), + (1004, 500420, 3), + (1004, 500423, 1), + (1004, 500426, 2), + (1004, 500429, 3), + (1004, 500432, 1), + (1004, 500435, 2), + (1004, 500438, 3), + (1004, 500441, 1), + (1004, 500444, 2), + (1004, 500447, 3), + (1004, 500450, 1), + (1004, 500453, 2), + (1004, 500456, 3), + (1004, 500459, 1), + (1004, 500462, 2), + (1004, 500465, 3), + (1004, 500468, 1), + (1004, 500471, 2), + (1004, 500474, 3), + (1004, 500477, 1), + (1004, 500480, 2), + (1004, 500483, 3), + (1004, 500486, 1), + (1004, 500489, 2), + (1004, 500492, 3), + (1004, 500495, 1), + (1004, 500498, 2), + (1004, 500501, 3), + (1004, 500504, 1), + (1004, 500507, 2), + (1004, 500510, 3), + (1004, 500513, 1), + (1004, 500516, 2), + (1004, 500519, 3), + (1004, 500522, 1), + (1004, 500525, 2), + (1004, 500528, 3), + (1004, 500531, 1), + (1004, 500534, 2), + (1004, 500537, 3), + (1004, 500540, 1), + (1004, 500543, 2), + (1004, 500546, 3), + (1004, 500549, 1), + (1004, 500552, 2), + (1004, 500555, 3), + (1004, 500558, 1), + (1004, 500561, 2), + (1004, 500564, 3), + (1004, 500567, 1), + (1004, 500570, 2), + (1004, 500573, 3), + (1004, 500576, 1), + (1004, 500579, 2), + (1004, 500582, 3), + (1004, 500585, 1), + (1004, 500588, 2), + (1004, 500591, 3), + (1004, 500594, 1), + (1004, 500597, 2), + (1004, 500600, 3), + (1004, 500603, 1), + (1004, 500606, 2), + (1004, 500609, 3), + (1004, 500612, 1), + (1004, 500615, 2), + (1004, 500618, 3), + (1004, 500621, 1), + (1004, 500624, 2), + (1004, 500627, 3), + (1004, 500630, 1), + (1004, 500633, 2), + (1004, 500636, 3), + (1004, 500639, 1), + (1004, 500642, 2), + (1004, 500645, 3), + (1004, 500648, 1), + (1004, 500651, 2), + (1004, 500654, 3), + (1004, 500657, 1), + (1004, 500660, 2), + (1004, 500663, 3), + (1004, 500666, 1), + (1004, 500669, 2), + (1004, 500672, 3), + (1004, 500675, 1), + (1004, 500678, 2), + (1004, 500681, 3), + (1004, 500684, 1), + (1004, 500687, 2), + (1004, 500690, 3), + (1004, 500693, 1), + (1004, 500696, 2), + (1004, 500699, 3), + (1004, 500702, 1), + (1004, 500705, 2), + (1004, 500708, 3), + (1004, 500711, 1), + (1004, 500714, 2), + (1004, 500717, 3), + (1004, 500720, 1), + (1004, 500723, 2), + (1004, 500726, 3), + (1004, 500729, 1), + (1004, 500732, 2), + (1004, 500735, 3), + (1004, 500738, 1), + (1004, 500741, 2), + (1004, 500744, 3), + (1004, 500747, 1), + (1004, 500750, 2), + (1004, 500753, 3), + (1004, 500756, 1), + (1004, 500759, 2), + (1004, 500762, 3), + (1004, 500765, 1), + (1004, 500768, 2), + (1004, 500771, 3), + (1004, 500774, 1), + (1004, 500777, 2), + (1004, 500780, 3), + (1004, 500783, 1), + (1004, 500786, 2), + (1004, 500789, 3), + (1004, 500792, 1), + (1004, 500795, 2), + (1004, 500798, 3), + (1004, 500801, 1), + (1004, 500804, 2), + (1004, 500807, 3), + (1004, 500810, 1), + (1004, 500813, 2), + (1004, 500816, 3), + (1004, 500819, 1), + (1004, 500822, 2), + (1004, 500825, 3), + (1004, 500828, 1), + (1004, 500831, 2), + (1004, 500834, 3), + (1004, 500837, 1), + (1004, 500840, 2), + (1004, 500843, 3), + (1004, 500846, 1), + (1004, 500849, 2), + (1004, 500852, 3), + (1004, 500855, 1), + (1004, 500858, 2), + (1004, 500861, 3), + (1004, 500864, 1), + (1004, 500867, 2), + (1004, 500870, 3), + (1004, 500873, 1), + (1004, 500876, 2), + (1004, 500879, 3), + (1004, 500882, 1), + (1004, 500885, 2), + (1004, 500888, 3), + (1004, 500891, 1), + (1004, 500894, 2), + (1004, 500897, 3), + (1004, 500900, 1); +INSERT INTO acore_characters.`character_talent` (`guid`, `spell`, `specMask`) VALUES + (1004, 900001, 1), + (1004, 900002, 1), + (1004, 900003, 1), + (1004, 900004, 1), + (1004, 900005, 1); +INSERT INTO acore_characters.`character_glyphs` (`guid`, `talentGroup`, `glyph1`, `glyph2`, `glyph3`, `glyph4`, `glyph5`, `glyph6`) VALUES + (1004, 0, 1, 2, 3, 4, 5, 6), + (1004, 1, 7, 0, 0, 0, 0, 0); +INSERT INTO acore_characters.`character_skills` (`guid`, `skill`, `value`, `max`) VALUES + (1004, 100, 300, 450), + (1004, 101, 301, 450), + (1004, 102, 302, 450), + (1004, 103, 303, 450), + (1004, 104, 304, 450), + (1004, 105, 305, 450), + (1004, 106, 306, 450), + (1004, 107, 307, 450), + (1004, 108, 308, 450), + (1004, 109, 309, 450); +INSERT INTO acore_characters.`character_settings` (`guid`, `source`, `data`) VALUES + (1004, _utf8mb4 0x636f72652e617363656e73696f6e5f6163746976655f73706563, _utf8mb4 0x353420), + (1004, _utf8mb4 0x636f72652e617363656e73696f6e5f73746172746572, _utf8mb4 0x3120), + (1004, _utf8mb4 0x636f72652e617363656e73696f6e5f6275696c642e3534, _utf8mb4 0x3320353637313020353633323020393031303120), + (1004, _utf8mb4 0x636f72652e617363656e73696f6e5f6261722e3534, _utf8mb4 0x3220302035303030303320312035303030303620), + (1004, _utf8mb4 0x636f72652e617363656e73696f6e5f736c6f742e616374697665, _utf8mb4 0x3020), + (1004, _utf8mb4 0x636f72652e7370656c6c5f6368617267652e383034313937, _utf8mb4 0x32203137393030303030303020), + (1004, _utf8mb4 0x636f612e626f742e67656172, _utf8mb4 0x312032203320), + (1004, _utf8mb4 0x636f612e676561725f707265665f776561706f6e, _utf8mb4 0x3220), + (1004, _utf8mb4 0x6d6f642e6578616d706c652e6e65775f66656174757265, _utf8mb4 0x392038203720), + (1004, _utf8mb4 0x636f72652e77696c64636172642e6361726473, _utf8mb4 0x31203220); +INSERT INTO acore_characters.`character_account_data` (`guid`, `type`, `time`, `data`) VALUES + (1004, 5, 1790000000, 0xfd2992936477103705783b2983ecdabc6f022b53ff446c4155ea1e0e31df205d8b3fc6f87451b67413fd007d6b323f14d2fe5614dab33ba9139d96f75efe4e174239ed1136fc75f79a48242521e33aee5a6f823526d45d0bce04ea37be3af121dd56a5fb7426d3f9e8b71b94d4206be32d2acf91f3dd3ae245f707fd03e94ee0dab632509d06d513dc0f8890ea7c3948cc225bdcbb0c8af86cd220b053d96edaf1447490f93185d89f27d586c80f528a4a487656ef877af17d72dbc23e00ed38e64e2aa1cb0016697726654cbae0465ccc0004677c123bc01ed87e7238e14295cdbbbf62de4b7faedc776e0e9c0d6a047568d3719575223e440faa36f1c5ef21ff2efd915a8b3ab8234101e50332c8379d4e27fc28857ec526b00c50cbe696ae954521913ea5066031762940e310a5a4277ddaabb670afcc984e06b3c55f3e0bead7e755f14a3e9fe98c46e9a32b2640668918ab1097c40fa5471006036f036469813f251e49c242543c82523bab6e3cc5f165786319c50034233d86b4adbb9cc7e105754fff50808b70322090ccf883c207b250e0388124aa04fd08124d1f5f720de546ca8e73ddc9e71bb1c5a0df67b65ccc8afcede46054cfd44b452b322d76b54cb041d9bb49f0ccc5ea584c30cd67bfe1dc599924483f019e05500eb6584a2f7afcf838555047c3c901c74dd155e9ec10d3efdb7a63ced430e92b6478676b56bdb7c204d131962aa83f14c7490d31847cad304928dd3bf148bae93dd0d82d1a361a455f6caa3dbd1705f0281cfff36ca6488f367560221d2c1bf44dbf05a48b9ab810f4a870e5e64a53181aad6ab9ac484363468d130001ff20656e64), + (1004, 1, 1790000001, 0x69676e6f72656420636f6e666967206361636865); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1005, 5001, _utf8mb4 0x48756e7479, 4, 14, 0, 60, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 2, 0, NULL); +INSERT INTO acore_characters.`character_pet` (`id`, `entry`, `owner`, `modelid`, `CreatedBySpell`, `PetType`, `level`, `exp`, `Reactstate`, `name`, `renamed`, `slot`, `curhealth`, `curmana`, `curhappiness`, `savetime`, `abdata`) VALUES + (3001, 42, 1005, 901, 1515, 1, 60, 1000, 1, _utf8mb4 0x526578, 0, 0, 5000, 100, 1000000, 1790000000, _utf8mb4 0x372032203020302031203020312031203020), + (3002, 43, 1005, 902, 1515, 1, 55, 200, 1, _utf8mb4 0x46616e67, 1, 1, 4000, 90, 900000, 1790000000, _utf8mb4 0x37203220), + (3003, 416, 1005, 4449, 688, 0, 60, 0, 1, _utf8mb4 0x496d70, 0, 100, 3000, 400, 0, 1790000000, NULL); +INSERT INTO acore_characters.`pet_spell` (`guid`, `spell`, `active`) VALUES + (3001, 17253, 1), + (3001, 16827, 0), + (3001, 24604, 1), + (3001, 61683, 0), + (3001, 34889, 1), + (3001, 50256, 0), + (3003, 3110, 1); +INSERT INTO acore_characters.`character_pet_declinedname` (`id`, `owner`, `genitive`, `dative`, `accusative`, `instrumental`, `prepositional`) VALUES + (3002, 1005, _utf8mb4 0xd0a4d0b0d0bdd0b3d0b0, _utf8mb4 0xd0a4d0b0d0bdd0b3d183, _utf8mb4 0xd0a4d0b0d0bdd0b3, _utf8mb4 0xd0a4d0b0d0bdd0b3d0bed0bc, _utf8mb4 0xd0a4d0b0d0bdd0b3d0b5); +INSERT INTO acore_characters.pet_aura (guid, casterGuid, spell, effectMask, recalculateMask, stackCount, maxDuration, remainTime, remainCharges) VALUES (3001, 1005, 99, 1, 0, 1, 1000, 500, 0); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1006, 5001, _utf8mb4 0x4f6e6c696e65, 1, 12, 0, 10, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1007, 5001, _utf8mb4 0x48617264636f7265, 1, 12, 0, 10, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.coa_character_gamemode (guid, gameMode) VALUES (1007, 1); +INSERT INTO acore_characters.coa_character_challenge (guid, challengeId, level, deaths, hunger, thirst, startTime) VALUES (1007, 5, 1, 0, 90, 90, 1790000000); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1008, 5001, _utf8mb4 0x436163686579, 1, 12, 0, 30, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.item_instance (guid, itemEntry, owner_guid, enchantments) VALUES (30001, 900001, 1008, '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '); +INSERT INTO acore_characters.ascension_manastorm_cache (item, guid) VALUES (30001, 1008); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1009, 5001, _utf8mb4 0x44656c65746564, 1, 12, 0, 20, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, 1790000000); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1010, 5002, _utf8mb4 0x426f747479, 1, 12, 0, 80, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1011, 5003, _utf8mb4 0x4d6f646479, 1, 12, 0, 50, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.mod_unknown_state (guid, note) VALUES (1011, 'data this Manager does not know'); +INSERT INTO acore_characters.`characters` (`guid`, `account`, `name`, `race`, `class`, `gender`, `level`, `xp`, `money`, `skin`, `face`, `hairStyle`, `hairColor`, `facialStyle`, `bankSlots`, `playerFlags`, `taximask`, `online`, `arenaPoints`, `totalHonorPoints`, `todayHonorPoints`, `yesterdayHonorPoints`, `totalKills`, `todayKills`, `yesterdayKills`, `chosenTitle`, `knownCurrencies`, `watchedFaction`, `talentGroupsCount`, `activeTalentGroup`, `exploredZones`, `knownTitles`, `actionBars`, `extraBonusTalentCount`, `resettalents_cost`, `stable_slots`, `innTriggerId`, `deleteDate`) VALUES + (1012, 5001, _utf8mb4 0x486973746f7279, 1, 12, 0, 60, 0, 0, 1, 2, 3, 4, 0, 0, 0, _utf8mb4 0x3020302030203020, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, _utf8mb4 0x3020302030203020, _utf8mb4 0x302030203020302030203020, 0, 0, 0, 0, 0, NULL); +INSERT INTO acore_characters.coa_character_gamemode (guid, gameMode) VALUES (1012, 0); +INSERT INTO acore_characters.coa_challenge_completion (guid, challengeId, level, completeTime, startTime) VALUES (1012, 5, 1, 1790000100, 1790000000); +INSERT INTO acore_characters.coa_character_condition (guid, flag) VALUES (1012, 'finished_once'); diff --git a/crates/coa-core/src/portable/realm/tests.rs b/crates/coa-core/src/portable/realm/tests.rs new file mode 100644 index 0000000..16348a1 --- /dev/null +++ b/crates/coa-core/src/portable/realm/tests.rs @@ -0,0 +1,444 @@ +//! Exporter tests on **recorded answers of a real database** (`testdata/golden/`, recorded by `live.rs` from the +//! synthetic characters of `testdata/realm-fixture.sql`). They need no database. `live.rs` re-records and verifies +//! the same answers against a real disposable MySQL. + +use std::collections::HashMap; + +use super::blockers::Blocker; +use super::export::{build, ExportRequest, Exported}; +use super::script::{self, RawExport, SchemaProbe}; +use super::*; +use crate::portable::ids::{CharacterId, ContentId, PortableItemId}; +use crate::portable::model::*; +use crate::portable::snapshot; +use crate::portable::store::{ItemObservation, MappingState, Store}; + +const PROBE: &str = include_str!("testdata/golden/probe.txt"); +const LIST: &str = include_str!("testdata/golden/list.txt"); + +fn answer(guid: u32) -> &'static str { + match guid { + 1001 => include_str!("testdata/golden/export-1001.txt"), + 1002 => include_str!("testdata/golden/export-1002.txt"), + 1003 => include_str!("testdata/golden/export-1003.txt"), + 1004 => include_str!("testdata/golden/export-1004.txt"), + 1005 => include_str!("testdata/golden/export-1005.txt"), + 1006 => include_str!("testdata/golden/export-1006.txt"), + 1007 => include_str!("testdata/golden/export-1007.txt"), + 1008 => include_str!("testdata/golden/export-1008.txt"), + 1009 => include_str!("testdata/golden/export-1009.txt"), + 1010 => include_str!("testdata/golden/export-1010.txt"), + 1011 => include_str!("testdata/golden/export-1011.txt"), + 1012 => include_str!("testdata/golden/export-1012.txt"), + other => panic!("no recorded answer for {other}"), + } +} + +fn probe() -> SchemaProbe { + script::parse_probe(PROBE).unwrap() +} + +fn raw(guid: u32) -> RawExport { + script::parse_output(answer(guid), &script::queries(guid, &probe()).unwrap()).unwrap() +} + +fn export_as(guid: u32, ruleset: Ruleset, prior: &HashMap) -> Result { + build(&raw(guid), &ExportRequest { ruleset, local_guid: guid, character_id: None, prior_items: prior }) +} + +fn export(guid: u32) -> Exported { + export_as(guid, Ruleset::Coa, &HashMap::new()).unwrap_or_else(|e| panic!("export of {guid} failed: {e}")) +} + +fn roundtrip(model: &PortableCharacter) { + let encoded = snapshot::encode(model).unwrap(); + let back = snapshot::decode(&encoded.payload, Some(&encoded.content_hash)).unwrap(); + assert_eq!(&back, model, "DB -> snapshot -> serialize -> deserialize must be structurally equal"); +} + +fn blockers_of(guid: u32) -> Vec { + match export_as(guid, Ruleset::Coa, &HashMap::new()) { + Err(PortableError::NotExportable(b)) => b, + other => panic!("{guid} should be refused, got {:?}", other.map(|e| e.model.identity.name)), + } +} + +fn item_at(model: &PortableCharacter, container: Option, slot: u8) -> &PortableItem { + model.items.iter().find(|i| i.container == container && i.slot == slot).unwrap_or_else(|| panic!("no item at {container:?}/{slot}")) +} + +// ---- the characters ----------------------------------------------------------------------------------------------- + +#[test] +fn a_naked_level_one_character() { + let e = export(1001); + let m = &e.model; + assert_eq!((m.identity.name.as_str(), m.progression.level, m.progression.money), ("Naked", 1, 0)); + assert_eq!((m.identity.race.to_string().as_str(), m.identity.class.to_string().as_str()), ("coa:race:1", "coa:class:12")); + assert_eq!(m.ruleset, Ruleset::Coa); + assert!(m.items.is_empty() && m.build.spells.is_empty() && m.pets.is_empty() && m.settings.is_empty() && m.extensions.is_empty()); + assert!(e.observations.is_empty() && e.warnings.is_empty()); + roundtrip(m); +} + +#[test] +fn a_geared_character_with_bags_enchants_gems_and_special_items() { + let e = export(1002); + let m = &e.model; + assert_eq!(m.identity.name, "Geared"); + assert_eq!((m.identity.gender, m.progression.level, m.progression.xp, m.progression.money), (1, 80, 12345, 200_060_523)); + assert_eq!(m.identity.class.to_string(), "coa:class:21"); + assert_eq!(m.identity.cosmetic_flags, 0x400, "of playerFlags 0x404 only the cosmetic bit is carried"); + assert_eq!((m.progression.honor.arena_points, m.progression.honor.total_honor, m.progression.honor.total_kills), (150, 4092, 777)); + assert_eq!((m.progression.known_currencies, m.progression.chosen_title, m.progression.watched_faction), (165, 5, 72)); + assert_eq!((m.progression.bank_slots, m.progression.stable_slots, m.progression.action_bars_mask, m.build.extra_bonus_talent_count), (4, 2, 15, 2)); + assert_eq!(m.progression.explored_zones.split_whitespace().count(), 128); + assert_eq!(m.build.spells.len(), 60); + assert!(m.build.spells.windows(2).all(|w| w[0].0 < w[1].0)); + assert_eq!(m.reputation.len(), 20); + + // 19 equipped + 4 bags + 24 in bags + 8 backpack + book + 2 bank + currency + gift = 60; + // the three rows the realm would clean up itself are left out, and said so + assert_eq!(m.items.len(), 60); + assert_eq!(e.observations.len(), 60); + assert_eq!(e.warnings.len(), 3, "{:?}", e.warnings); + assert!(e.warnings.iter().any(|w| w.contains("missing from item_instance"))); + assert!(e.warnings.iter().any(|w| w.contains("container 29999"))); + assert!(e.warnings.iter().any(|w| w.contains("buyback"))); + + // enchantments and gems keep their slots (permanent = 0, sockets 2..4) + let chest = item_at(m, None, 3); + assert_eq!(chest.entry.to_string(), format!("coa:item:{}", 30000 + 3 * 17)); + assert_eq!( + chest.enchantments, + vec![ + Enchantment { slot: 0, id: 3003, duration: 0, charges: 0 }, + Enchantment { slot: 2, id: 3878, duration: 0, charges: 0 }, + Enchantment { slot: 3, id: 3879, duration: 0, charges: 0 }, + Enchantment { slot: 4, id: 3880, duration: 0, charges: 0 }, + ] + ); + assert!(item_at(m, None, 4).enchantments.is_empty()); + assert_eq!(item_at(m, None, 5).random_property_id, -57, "a suffix stays negative"); + assert_eq!(item_at(m, None, 4).creator_name.as_deref(), Some("Naked"), "the crafter is carried by name, never by guid"); + assert_eq!(item_at(m, None, 7).durability, 97); + + // bags and their contents + let bag = item_at(m, None, 19); + assert_eq!(bag.entry.to_string(), "coa:item:41019"); + let in_bag: Vec<&PortableItem> = m.items.iter().filter(|i| i.container == Some(bag.id)).collect(); + assert_eq!(in_bag.len(), 6); + assert_eq!((item_at(m, Some(bag.id), 2).count, item_at(m, Some(bag.id), 1).count), (9, 5)); + assert!(m.items.iter().filter(|i| i.container.is_some()).all(|i| m.items.iter().any(|b| Some(b.id) == i.container && b.container.is_none()))); + + // item state outside the plain columns + let book = item_at(m, None, 39); + assert_eq!(book.text.as_deref(), Some("A book.\nSecond line\twith a tab, a \"quote\", an 'apostrophe', a \\ backslash and \u{4e2d}\u{6587}.")); + assert_eq!(item_at(m, None, 40).charges, vec![-1, 0, 0, 0, 0]); + assert_eq!(item_at(m, None, 40).duration, 3600); + assert!(item_at(m, None, 41).charges.is_empty(), "NULL charges"); + let token = item_at(m, None, 118); + assert_eq!((token.entry.to_string().as_str(), token.count), ("coa:item:375250", 12), "currency tokens ride in their slot"); + let wrapped = item_at(m, None, 42); + assert_eq!(wrapped.gift, Some(Gift { entry: ContentId::new("coa", "item", 8000).unwrap(), flags: 8 })); + + roundtrip(m); + m.validate().unwrap(); +} + +#[test] +fn quests_reputation_and_action_bars() { + let m = export(1003).model; + assert_eq!(m.quests.active.len(), 2); + assert_eq!(m.quests.active[0], ActiveQuest { quest: 12001, status: 3, explored: false, timer: 0, mob_counts: [3, 0, 0, 0], item_counts: [0; 6], player_count: 0 }); + assert_eq!(m.quests.active[1], ActiveQuest { quest: 12002, status: 1, explored: true, timer: 600, mob_counts: [0; 4], item_counts: [2, 0, 0, 0, 0, 0], player_count: 0 }); + assert_eq!(m.quests.rewarded, vec![12000, 12003, 12004], "a rewarded row with active = 0 is not a completed quest to the realm either"); + assert_eq!(m.reputation.len(), 10); + assert_eq!(m.reputation[3], ReputationEntry { faction: 4, standing: 200, flags: 1 }); + assert_eq!(m.actions.len(), 17); + assert_eq!(m.actions.iter().filter(|a| a.spec == 1).count(), 5); + assert!(m.actions.contains(&ActionButton { spec: 1, button: 4, action: 7, kind: 64 }), "macro buttons keep their type"); + assert_eq!(m.progression.level, 40); + roundtrip(&m); +} + +#[test] +fn spells_talents_glyphs_skills_settings_and_macros() { + let e = export(1004); + let m = &e.model; + assert_eq!(m.identity.name, "\u{414}\u{440}\u{430}\u{43a}\u{43e}\u{43d}"); + assert_eq!(m.build.spells.len(), 300); + assert_eq!(m.build.spells[0], (500_003, 2)); + assert_eq!(m.build.talents.len(), 5); + assert_eq!(m.build.glyphs, vec![GlyphSet { talent_group: 0, glyphs: [1, 2, 3, 4, 5, 6] }, GlyphSet { talent_group: 1, glyphs: [7, 0, 0, 0, 0, 0] }]); + assert_eq!(m.build.skills.len(), 10); + assert_eq!(m.build.skills[0], Skill { skill: 100, value: 300, max: 450 }); + + // CoA gameplay state: carried + assert_eq!(m.settings["core.ascension_active_spec"], vec![54]); + assert_eq!(m.settings["core.ascension_starter"], vec![1]); + assert_eq!(m.settings["core.ascension_build.54"], vec![3, 56710, 56320, 90101]); + assert_eq!(m.settings["core.ascension_bar.54"], vec![2, 0, 500_003, 1, 500_006]); + assert_eq!(m.settings["core.ascension_slot.active"], vec![0]); + assert_eq!(m.settings["core.spell_charge.804197"], vec![2, 1_790_000_000]); + // bots: dropped; unknown / other rulesets' state: kept aside, not carried + assert!(!m.settings.contains_key("coa.bot.gear")); + for aside in ["coa.gear_pref_weapon", "mod.example.new_feature", "core.wildcard.cards"] { + assert!(!m.settings.contains_key(aside), "{aside} must not be carried"); + } + let ext = &m.extensions["coa:unlisted-settings"]; + assert!(ext.is_intact()); + let aside: std::collections::BTreeMap> = serde_json::from_slice(&ext.payload.0).unwrap(); + assert_eq!(aside.keys().map(String::as_str).collect::>(), vec!["coa.gear_pref_weapon", "core.wildcard.cards", "mod.example.new_feature"]); + assert_eq!(aside["mod.example.new_feature"], vec![9, 8, 7]); + assert!(e.warnings.iter().any(|w| w.contains("kept aside"))); + + // macros are carried as the binary blob they are; the other client data is not + assert_eq!(m.client_data.keys().copied().collect::>(), vec![5]); + let macros = &m.client_data[&5]; + assert_eq!(macros.time, 1_790_000_000); + assert_eq!(macros.data.0.len(), 607); + assert!(macros.data.0.ends_with(b"\x00\x01\xff end")); + roundtrip(m); +} + +#[test] +fn hunter_and_summoned_pets() { + let m = export(1005).model; + assert_eq!(m.pets.len(), 3); + let [current, stabled, summon] = [&m.pets[0], &m.pets[1], &m.pets[2]]; + assert_eq!((current.name.as_str(), current.slot, current.pet_type, current.level), ("Rex", 0, 1, 60)); + assert_eq!((current.entry.to_string().as_str(), current.model_id, current.created_by_spell, current.health), ("coa:creature:42", 901, 1515, 5000)); + assert_eq!(current.spells.len(), 6); + assert_eq!(current.spells[0], PetSpell { spell: 16827, active: 0 }); + assert_eq!(current.action_bar, "7 2 0 0 1 0 1 1 0 "); + assert_eq!((stabled.name.as_str(), stabled.slot, stabled.renamed), ("Fang", 1, true)); + let declined = stabled.declined_names.as_ref().unwrap(); + assert_eq!(declined[0], "\u{424}\u{430}\u{43d}\u{433}\u{430}"); + assert!(current.declined_names.is_none()); + assert_eq!((summon.name.as_str(), summon.slot, summon.pet_type), ("Imp", 100, 0)); + assert_eq!(summon.spells, vec![PetSpell { spell: 3110, active: 1 }]); + assert_eq!(summon.action_bar, "", "a NULL action bar is an empty one"); + assert_eq!(m.progression.stable_slots, 2); + let ids: std::collections::HashSet<_> = m.pets.iter().map(|p| p.id).collect(); + assert_eq!(ids.len(), 3, "every pet has its own portable id"); + roundtrip(&m); +} + +// ---- who may be exported ------------------------------------------------------------------------------------------------ + +#[test] +fn offline_challenge_free_characters_are_exportable() { + for guid in [1001, 1002, 1003, 1004, 1005, 1012] { + assert!(super::export::blockers(&raw(guid)).unwrap().is_empty(), "{guid}"); + } + // history is not an active state: a finished challenge, game mode 0 and condition flags do not block + assert_eq!(export(1012).model.identity.name, "History"); +} + +#[test] +fn every_blocking_state_refuses_the_export() { + assert_eq!(blockers_of(1006), vec![Blocker::Online]); + assert_eq!(blockers_of(1007), vec![Blocker::ActiveChallenge, Blocker::ActiveGameMode]); + assert_eq!(blockers_of(1008), vec![Blocker::PendingManastormCaches]); + assert_eq!(blockers_of(1009), vec![Blocker::Deleted]); + assert_eq!(blockers_of(1010), vec![Blocker::BotAccount]); + assert_eq!(blockers_of(1011), vec![Blocker::UnclassifiedState("mod_unknown_state".into())]); + assert!(blockers_of(1007).iter().all(Blocker::is_challenge_state), "decision D6: challenge, game mode and Manastorm state block transfer"); + let message = PortableError::NotExportable(blockers_of(1007)).to_string(); + assert!(message.contains("challenge") && message.contains("game mode"), "{message}"); +} + +#[test] +fn the_character_list_agrees_with_the_export() { + let list = parse_listing(LIST).unwrap(); + assert_eq!(list.len(), 11, "twelve fixture characters, minus the bot"); + let find = |g: u32| list.iter().find(|c| c.local_guid == g).unwrap(); + assert_eq!((find(1002).name.as_str(), find(1002).level, find(1002).class, find(1002).race), ("Geared", 80, 21, 2)); + assert_eq!(find(1004).name, "\u{414}\u{440}\u{430}\u{43a}\u{43e}\u{43d}"); + assert!(find(1001).eligible() && find(1012).eligible()); + assert_eq!(find(1006).blockers, vec![Blocker::Online]); + assert_eq!(find(1007).blockers, vec![Blocker::ActiveChallenge, Blocker::ActiveGameMode]); + assert_eq!(find(1008).blockers, vec![Blocker::PendingManastormCaches]); + assert_eq!(find(1009).blockers, vec![Blocker::Deleted]); + // the listing is cheap and cannot see unknown tables; the export refuses 1011 + assert!(find(1011).eligible()); + assert!(list.iter().all(|c| c.local_guid != 1010), "bots are not even listed"); + assert!(parse_listing("1\tx6162\t1\t1").is_err()); + assert!(parse_listing(&LIST.replace("x476561726564", "xZZ")).is_err()); +} + +#[test] +fn the_schema_probe_finds_the_unknown_per_character_table() { + let probe = probe(); + assert!(probe.missing_required().is_empty()); + assert_eq!(probe.unclassified_character_tables(), vec![("mod_unknown_state".to_string(), "guid".to_string())]); + let names: Vec = script::queries(1, &probe).unwrap().into_iter().map(|q| q.name).collect(); + for expected in ["block:challenge", "block:gamemode", "block:trial", "block:manastorm", "unclassified:mod_unknown_state"] { + assert!(names.contains(&expected.to_string()), "{expected}"); + } + // a realm that lacks a core table cannot be exported from + let mut broken = probe.clone(); + broken.tables.remove("item_instance"); + assert_eq!(broken.missing_required(), vec!["item_instance"]); +} + +// ---- identity of items, rulesets, robustness --------------------------------------------------------------------------- + +#[test] +fn items_keep_their_portable_ids_but_a_recycled_guid_gets_a_new_one() { + let first = export(1002); + let prior: HashMap = first.observations.iter().map(|o| (o.local_item_guid, (o.portable_item_id, o.identity.clone()))).collect(); + let again = export_as(1002, Ruleset::Coa, &prior).unwrap(); + let ids = |e: &Exported| e.model.items.iter().map(|i| i.id).collect::>(); + assert_eq!(ids(&first), ids(&again), "unchanged items keep their ids"); + assert_eq!(ids(&first).len(), 60, "every item has its own id"); + + // the realm recycled guid 20001: the mapping was made for a different item, so the item there now is a new one + let mut recycled = prior.clone(); + let (old_id, _) = recycled[&20001].clone(); + recycled.insert(20001, (old_id, "v1:some-other-item".to_string())); + let after = export_as(1002, Ruleset::Coa, &recycled).unwrap(); + let obs = after.observations.iter().find(|o| o.local_item_guid == 20001).unwrap(); + assert_ne!(obs.portable_item_id, old_id, "a recycled guid must not inherit the old item's identity"); + assert_eq!(after.observations.iter().filter(|o| o.local_item_guid != 20001).filter(|o| prior[&o.local_item_guid].0 == o.portable_item_id).count(), 59); + + // a mapping for a guid the realm no longer has is simply not used + let mut stale = prior; + stale.insert(99_999_999, (PortableItemId::new(), "v1:x".into())); + assert_eq!(export_as(1002, Ruleset::Coa, &stale).unwrap().observations.len(), 60); +} + +#[test] +fn a_reexport_keeps_the_portable_character_id() { + let id = CharacterId::new(); + let e = build(&raw(1002), &ExportRequest { ruleset: Ruleset::Coa, local_guid: 1002, character_id: Some(id), prior_items: &HashMap::new() }).unwrap(); + assert_eq!(e.model.character_id, id); +} + +#[test] +fn the_same_realm_data_gives_the_same_canonical_bytes() { + let prior = HashMap::new(); + let a = export_as(1004, Ruleset::Coa, &prior).unwrap().model; + let mut b = export_as(1004, Ruleset::Coa, &prior).unwrap().model; + // everything that is generated (ids) is aligned; everything that comes from the realm must be identical + b.character_id = a.character_id; + for (pa, pb) in a.pets.iter().zip(b.pets.iter_mut()) { + pb.id = pa.id; + } + assert_eq!(snapshot::content_hash(&a).unwrap(), snapshot::content_hash(&b).unwrap()); +} + +#[test] +fn the_wildcard_ruleset_reads_wildcard_state_and_uses_its_own_namespace() { + let coa = export_as(1004, Ruleset::Coa, &HashMap::new()).unwrap().model; + let wildcard = export_as(1004, Ruleset::Wildcard, &HashMap::new()).unwrap().model; + assert_eq!(wildcard.ruleset, Ruleset::Wildcard); + assert_eq!(wildcard.content_namespace, "wildcard"); + assert_eq!(wildcard.identity.class.to_string(), "wildcard:class:25"); + assert!(wildcard.settings.contains_key("core.wildcard.cards"), "Wildcard state is gameplay state on a Wildcard realm"); + assert!(!coa.settings.contains_key("core.wildcard.cards")); + // the realm profile of a database decides the ruleset, not the caller + let wc_db = Db::with_tools(std::path::PathBuf::new(), 1, "root", "x", Mode::Wildcard); + let coa_db = Db::with_tools(std::path::PathBuf::new(), 1, "root", "x", Mode::Coa); + assert_eq!((ruleset_of(&wc_db), ruleset_of(&coa_db)), (Ruleset::Wildcard, Ruleset::Coa)); + assert_eq!(wc_db.realm_schema(script::CHARACTERS_SCHEMA), "acore_characters_wildcard"); +} + +#[test] +fn windows_line_endings_do_not_matter() { + let crlf = answer(1002).replace("\r\n", "\n").replace('\n', "\r\n"); + let queries = script::queries(1002, &probe()).unwrap(); + let parsed = script::parse_output(&crlf, &queries).unwrap(); + let e = build(&parsed, &ExportRequest { ruleset: Ruleset::Coa, local_guid: 1002, character_id: None, prior_items: &HashMap::new() }).unwrap(); + assert_eq!((e.model.items.len(), e.model.identity.name.as_str()), (60, "Geared")); +} + +/// Whatever a damaged or hostile answer looks like, the exporter returns an error or a valid model, never panics. +#[test] +fn damaged_answers_never_panic() { + let queries = script::queries(1002, &probe()).unwrap(); + let original = answer(1002).as_bytes().to_vec(); + let mut x = 0x2545_F491u32; + let mut next = move || { + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + x + }; + let (mut errors, mut oks) = (0, 0); + for _ in 0..400 { + let mut bytes = original.clone(); + for _ in 0..1 + next() % 4 { + let at = next() as usize % bytes.len(); + bytes[at] = [b'Z', b'\t', b'\n', b'x', b'-', b'9', b'0', b'~'][next() as usize % 8]; + } + let Ok(text) = String::from_utf8(bytes) else { continue }; + match script::parse_output(&text, &queries).and_then(|raw| build(&raw, &ExportRequest { ruleset: Ruleset::Coa, local_guid: 1002, character_id: None, prior_items: &HashMap::new() })) { + Ok(e) => { + e.model.validate().unwrap(); + oks += 1; + } + Err(_) => errors += 1, + } + } + assert!(errors > 0, "some of the damage must be detected"); + assert_eq!(oks + errors, 400); +} + +#[test] +fn realm_errors_are_told_apart() { + let schema = realm_error(crate::Error::Invalid("database command failed: ERROR 1054 (42S22) at line 5: Unknown column 'c.nope' in 'field list'".into())); + assert!(matches!(schema, PortableError::SchemaMismatch(_))); + let down = realm_error(crate::Error::Invalid("The database is not running. Start the server first.".into())); + assert!(matches!(down, PortableError::RealmRead(_))); +} + +// ---- registering in the local store ---------------------------------------------------------------------------------------- + +#[test] +fn make_portable_registers_everything_in_one_step_and_refuses_twice() { + let mut store = Store::open_in_memory().unwrap(); + let profile = store.default_profile().unwrap(); + let exported = export(1002); + let expected_model = exported.model.clone(); + let observed = exported.observations.len(); + let made = register(&mut store, profile, "realm-a", exported).unwrap(); + assert_eq!(made.revision, 1); + assert_eq!(made.warnings.len(), 3); + + let record = store.character(made.character_id).unwrap(); + assert_eq!((record.revision, record.name.as_str(), record.level), (1, "Geared", 80)); + assert_eq!(store.load_current(made.character_id).unwrap(), expected_model); + assert_eq!(store.find_by_local("realm-a", 1002).unwrap(), Some(made.character_id)); + let mappings = store.server_mappings(made.character_id).unwrap(); + assert_eq!((mappings.len(), mappings[0].local_guid, mappings[0].last_revision), (1, 1002, 1)); + assert_eq!(mappings[0].state, MappingState::Synced); + assert_eq!(store.item_mappings(made.character_id, "realm-a").unwrap().len(), observed); + + // the same local character cannot be made portable twice + let again = register(&mut store, profile, "realm-a", export(1002)); + assert!(matches!(again, Err(PortableError::AlreadyPortable { local_guid: 1002, character, .. }) if character == made.character_id), "{again:?}"); + assert_eq!(store.list_characters(profile).unwrap().len(), 1); + + // a re-export with the store's mappings keeps every item id, so the next revision is a plain update + let lookup = store.active_item_lookup(made.character_id, "realm-a").unwrap(); + let re = build(&raw(1002), &ExportRequest { ruleset: Ruleset::Coa, local_guid: 1002, character_id: Some(made.character_id), prior_items: &lookup }).unwrap(); + assert_eq!(re.model, expected_model); + let revision = store.commit_snapshot(made.character_id, 1, re.model, "realm-a", Some("re-export")).unwrap(); + let report = store.reconcile_item_mappings(made.character_id, "realm-a", revision, &re.observations).unwrap(); + assert_eq!((report.confirmed, report.added, report.guid_reused, report.moved, report.absent), (observed, 0, 0, 0, 0)); +} + +#[test] +fn a_failed_registration_leaves_nothing_behind() { + let mut store = Store::open_in_memory().unwrap(); + let profile = store.default_profile().unwrap(); + let mut exported = export(1002); + // two observations for one local guid: the mapping step fails after the character was already inserted + let dup = exported.observations[0].clone(); + exported.observations.push(ItemObservation { portable_item_id: PortableItemId::new(), ..dup }); + assert!(register(&mut store, profile, "realm-a", exported).is_err()); + assert!(store.list_characters(profile).unwrap().is_empty(), "no half-registered character"); + assert_eq!(store.find_by_local("realm-a", 1002).unwrap(), None); +} diff --git a/crates/coa-core/src/portable/store.rs b/crates/coa-core/src/portable/store.rs index ede7e7f..4ca9c0e 100644 --- a/crates/coa-core/src/portable/store.rs +++ b/crates/coa-core/src/portable/store.rs @@ -10,7 +10,7 @@ use rusqlite::{params, Connection, OptionalExtension, Transaction, TransactionBe use super::collection::{valid_kind, IdSet}; use super::error::{PortableError, Result}; -use super::ids::{CharacterId, PortableItemId, ProfileId}; +use super::ids::{CharacterId, ContentId, PortableItemId, ProfileId}; use super::model::{PortableCharacter, Ruleset}; use super::snapshot::{self, EncodedSnapshot}; use super::versions::{PORTABLE_COLLECTION_FORMAT_VERSION, SNAPSHOT_FORMAT_VERSION}; @@ -18,7 +18,7 @@ use super::versions::{PORTABLE_COLLECTION_FORMAT_VERSION, SNAPSHOT_FORMAT_VERSIO pub const DATABASE_FILE: &str = "portable.db"; /// `PRAGMA application_id`: "COAP". Refuses to adopt an unrelated SQLite file. const APPLICATION_ID: i64 = 0x434F_4150; -const MIGRATIONS: &[&str] = &[include_str!("migrations/001_init.sql")]; +const MIGRATIONS: &[&str] = &[include_str!("migrations/001_init.sql"), include_str!("migrations/002_item_mapping_lifecycle.sql")]; pub const DEFAULT_HISTORY_KEEP: u32 = 20; pub const MAX_HISTORY_KEEP: u32 = 1_000; @@ -254,31 +254,7 @@ impl Store { let encoded = snapshot::encode(&model)?; let id = model.character_id; let tx = self.write_tx()?; - let exists: bool = tx.query_row("SELECT EXISTS(SELECT 1 FROM character WHERE character_id = ?1)", [id.to_string()], |r| r.get(0))?; - if exists { - return Err(PortableError::DuplicateCharacter(id)); - } - let profile_exists: bool = tx.query_row("SELECT EXISTS(SELECT 1 FROM profile WHERE profile_id = ?1)", [profile.to_string()], |r| r.get(0))?; - if !profile_exists { - return Err(PortableError::Invalid(format!("profile {profile} does not exist"))); - } - let at = now(); - tx.execute( - "INSERT INTO character(character_id, profile_id, ruleset, name, race, class, gender, level, revision, created_at, updated_at, archived) - VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, 1, ?9, ?9, 0)", - params![ - id.to_string(), - profile.to_string(), - model.ruleset.as_str(), - model.identity.name, - model.identity.race.to_string(), - model.identity.class.to_string(), - model.identity.gender, - model.progression.level, - at - ], - )?; - insert_snapshot(&tx, id, 1, &encoded, source_server_id, Some("created"), &at)?; + create_in_tx(&tx, profile, &model, &encoded, source_server_id)?; tx.commit()?; Ok(id) } @@ -395,34 +371,12 @@ impl Store { // ---- realm mappings ------------------------------------------------------------------------------------- /// Record (or update) the local guid of a portable character on a realm. A local guid can belong to one portable - /// character only. Changing the local guid of an existing binding drops that binding's item mappings (they named + /// character only. Changing the local guid of an existing binding retires that binding's item mappings (they named /// items of the previous local character). pub fn bind_server(&mut self, id: CharacterId, server_id: &str, local_guid: u32, last_revision: u64, state: MappingState) -> Result<()> { check_server_id(server_id)?; let tx = self.write_tx()?; - let record = read_character(&tx, id)?; - if last_revision > record.revision { - return Err(PortableError::Invalid(format!("revision {last_revision} is newer than the canonical revision {}", record.revision))); - } - let holder: Option = tx - .query_row("SELECT character_id FROM character_server_mapping WHERE server_id = ?1 AND local_guid = ?2", params![server_id, local_guid], |r| r.get(0)) - .optional()?; - if holder.is_some_and(|h| h != id.to_string()) { - return Err(PortableError::LocalGuidTaken { server_id: server_id.to_string(), local_guid }); - } - let previous: Option = tx - .query_row("SELECT local_guid FROM character_server_mapping WHERE character_id = ?1 AND server_id = ?2", params![id.to_string(), server_id], |r| r.get(0)) - .optional()?; - if previous.is_some_and(|p| p != local_guid as i64) { - tx.execute("DELETE FROM item_mapping WHERE character_id = ?1 AND server_id = ?2", params![id.to_string(), server_id])?; - } - tx.execute( - "INSERT INTO character_server_mapping(character_id, server_id, local_guid, last_revision, state, updated_at) - VALUES (?1, ?2, ?3, ?4, ?5, ?6) - ON CONFLICT(character_id, server_id) DO UPDATE SET local_guid = excluded.local_guid, last_revision = excluded.last_revision, - state = excluded.state, updated_at = excluded.updated_at", - params![id.to_string(), server_id, local_guid, last_revision as i64, state.as_str(), now()], - )?; + bind_in_tx(&tx, id, server_id, local_guid, last_revision, state)?; tx.commit()?; Ok(()) } @@ -449,49 +403,77 @@ impl Store { Ok(out) } - /// Replace the item mappings of one (character, realm) pair. Every portable item id and every local item guid may - /// appear once. The pair must already be bound with [`Store::bind_server`]. - pub fn set_item_mappings(&mut self, id: CharacterId, server_id: &str, mappings: &[(PortableItemId, u32)]) -> Result<()> { + /// Bring the item mappings of one (character, realm) pair in line with what the realm *actually* contains now. + /// `observations` must list **every** item of the character on that realm; `revision` is the canonical revision + /// the observation corresponds to. The pair must already be bound with [`Store::bind_server`]. + /// + /// Lifecycle (nothing is ever overwritten; old rows are retired and kept): + /// * same portable item, same local guid, same identity -> confirmed; + /// * the local guid is held by a mapping with another portable item or another identity -> the old mapping is + /// retired as `guid_reused` (the realm recycled the guid) and a new one is created; + /// * the portable item was mapped to another local guid -> that mapping is retired as `moved`; + /// * an active mapping that is no longer observed -> retired as `absent`. + pub fn reconcile_item_mappings(&mut self, id: CharacterId, server_id: &str, revision: u64, observations: &[ItemObservation]) -> Result { check_server_id(server_id)?; - let mut portable = std::collections::HashSet::new(); - let mut local = std::collections::HashSet::new(); - for (item, guid) in mappings { - if !portable.insert(*item) { - return Err(PortableError::Invalid(format!("portable item {item} is mapped twice"))); - } - if !local.insert(*guid) { - return Err(PortableError::ItemGuidConflict { server_id: server_id.to_string(), local_item_guid: *guid }); - } - } + validate_observations(server_id, observations)?; let tx = self.write_tx()?; - let bound: bool = tx.query_row( - "SELECT EXISTS(SELECT 1 FROM character_server_mapping WHERE character_id = ?1 AND server_id = ?2)", - params![id.to_string(), server_id], - |r| r.get(0), - )?; - if !bound { - return Err(PortableError::Invalid(format!("character {id} is not bound to server {server_id}"))); - } - tx.execute("DELETE FROM item_mapping WHERE character_id = ?1 AND server_id = ?2", params![id.to_string(), server_id])?; - { - let mut insert = tx.prepare("INSERT INTO item_mapping(character_id, server_id, portable_item_id, local_item_guid) VALUES (?1, ?2, ?3, ?4)")?; - for (item, guid) in mappings { - insert.execute(params![id.to_string(), server_id, item.to_string(), guid])?; - } - } + let report = reconcile_in_tx(&tx, id, server_id, revision, observations)?; tx.commit()?; - Ok(()) + Ok(report) } - pub fn item_mappings(&self, id: CharacterId, server_id: &str) -> Result> { - let mut stmt = self.conn.prepare("SELECT portable_item_id, local_item_guid FROM item_mapping WHERE character_id = ?1 AND server_id = ?2 ORDER BY local_item_guid")?; - let rows = stmt.query_map(params![id.to_string(), server_id], |r| Ok((r.get::<_, String>(0)?, r.get::<_, i64>(1)?)))?; - let mut out = Vec::new(); - for row in rows { - let (item, guid) = row?; - out.push((item.parse()?, guid as u32)); + /// Decide, for items just read from a realm, which portable item each one is. A local guid whose active mapping + /// was made for an item with a *different* identity is reported as [`ItemResolution::Reused`]: the realm recycled + /// that guid, the new item is not the old portable item and must get a new portable id. + pub fn resolve_item_ids(&self, id: CharacterId, server_id: &str, probes: &[(u32, &str)]) -> Result> { + probes + .iter() + .map(|(guid, identity)| { + Ok(match active_by_guid(&self.conn, id, server_id, *guid)? { + None => ItemResolution::Unmapped, + Some(m) if m.identity == *identity => ItemResolution::Known(m.portable_item_id), + Some(m) => ItemResolution::Reused { previous: m.portable_item_id }, + }) + }) + .collect() + } + + /// Active mappings of one (character, realm) pair, by local item guid. + pub fn item_mappings(&self, id: CharacterId, server_id: &str) -> Result> { + read_item_mappings(&self.conn, id, server_id, false) + } + + /// Every mapping ever made for the pair, retired ones included. + pub fn item_mapping_history(&self, id: CharacterId, server_id: &str) -> Result> { + read_item_mappings(&self.conn, id, server_id, true) + } + + /// Make a realm character portable in **one transaction**: the new portable character (revision 1), its binding to + /// the realm (state `synced`, revision 1) and its item mappings. Either all of it exists afterwards or none of it. + /// A local character that is already portable is refused. + pub fn register_realm_character(&mut self, r: RealmRegistration<'_>) -> Result { + check_server_id(r.source_server_id)?; + check_server_id(r.server_id)?; + let encoded = snapshot::encode(&r.model)?; + let id = r.model.character_id; + let tx = self.write_tx()?; + let holder: Option = tx + .query_row("SELECT character_id FROM character_server_mapping WHERE server_id = ?1 AND local_guid = ?2", params![r.server_id, r.local_guid], |row| row.get(0)) + .optional()?; + if let Some(existing) = holder { + return Err(PortableError::AlreadyPortable { server_id: r.server_id.to_string(), local_guid: r.local_guid, character: existing.parse()? }); } - Ok(out) + create_in_tx(&tx, r.profile, &r.model, &encoded, r.source_server_id)?; + bind_in_tx(&tx, id, r.server_id, r.local_guid, 1, MappingState::Synced)?; + reconcile_in_tx(&tx, id, r.server_id, 1, r.observations)?; + tx.commit()?; + Ok(id) + } + + /// Active item mappings as a lookup by local item guid: what a re-export hands to the exporter so that items keep + /// their portable ids (and recycled guids do not). + pub fn active_item_lookup(&self, id: CharacterId, server_id: &str) -> Result> { + Ok(read_item_mappings(&self.conn, id, server_id, false)?.into_iter().map(|m| (m.local_item_guid, (m.portable_item_id, m.identity))).collect()) } // ---- collections ---------------------------------------------------------------------------------------- @@ -668,5 +650,297 @@ fn read_snapshot_row(conn: &Connection, id: CharacterId, revision: u64) -> Resul Ok((model, EncodedSnapshot { content_hash: hash, uncompressed_size: size as u64, payload })) } +/// Everything needed to register a character exported from a realm. +pub struct RealmRegistration<'a> { + pub profile: ProfileId, + pub model: PortableCharacter, + /// Where the snapshot came from (recorded on revision 1). + pub source_server_id: &'a str, + pub server_id: &'a str, + pub local_guid: u32, + pub observations: &'a [ItemObservation], +} + +/// What a realm currently holds for one item of a character. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ItemObservation { + pub portable_item_id: PortableItemId, + pub local_item_guid: u32, + pub entry: ContentId, + /// See [`super::identity::item_identity`]. + pub identity: String, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum RetireReason { + GuidReused, + Moved, + Absent, + CharacterRebound, +} + +impl RetireReason { + pub fn as_str(self) -> &'static str { + match self { + RetireReason::GuidReused => "guid_reused", + RetireReason::Moved => "moved", + RetireReason::Absent => "absent", + RetireReason::CharacterRebound => "character_rebound", + } + } + fn parse(s: &str) -> Result { + Ok(match s { + "guid_reused" => RetireReason::GuidReused, + "moved" => RetireReason::Moved, + "absent" => RetireReason::Absent, + "character_rebound" => RetireReason::CharacterRebound, + other => return Err(PortableError::Invalid(format!("unknown retire reason {other:?}"))), + }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ItemMapping { + pub portable_item_id: PortableItemId, + pub local_item_guid: u32, + pub entry: String, + pub identity: String, + pub active: bool, + pub created_revision: u64, + pub confirmed_revision: u64, + pub retired_revision: Option, + pub retired_reason: Option, +} + +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub struct ReconcileReport { + pub confirmed: usize, + pub added: usize, + pub guid_reused: usize, + pub moved: usize, + pub absent: usize, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ItemResolution { + /// The guid is mapped and the item is still the one that was mapped. + Known(PortableItemId), + /// The guid was mapped for a different item: the realm recycled it. + Reused { previous: PortableItemId }, + /// Never mapped. + Unmapped, +} + +struct ActiveRow { + mapping_id: i64, + portable_item_id: PortableItemId, + identity: String, +} + +fn active_by_guid(conn: &Connection, id: CharacterId, server_id: &str, guid: u32) -> Result> { + active_row( + conn, + "SELECT mapping_id, portable_item_id, identity FROM item_mapping WHERE character_id = ?1 AND server_id = ?2 AND local_item_guid = ?3 AND state = 'active'", + params![id.to_string(), server_id, guid], + ) +} + +fn active_by_item(conn: &Connection, id: CharacterId, server_id: &str, item: PortableItemId) -> Result> { + active_row( + conn, + "SELECT mapping_id, portable_item_id, identity FROM item_mapping WHERE character_id = ?1 AND server_id = ?2 AND portable_item_id = ?3 AND state = 'active'", + params![id.to_string(), server_id, item.to_string()], + ) +} + +fn active_row(conn: &Connection, sql: &str, params: impl rusqlite::Params) -> Result> { + let row = conn.query_row(sql, params, |r| Ok((r.get::<_, i64>(0)?, r.get::<_, String>(1)?, r.get::<_, String>(2)?))).optional()?; + row.map(|(mapping_id, item, identity)| Ok(ActiveRow { mapping_id, portable_item_id: item.parse()?, identity })).transpose() +} + +fn retire_one(tx: &Transaction<'_>, mapping_id: i64, reason: RetireReason, revision: u64, at: &str) -> Result<()> { + tx.execute( + "UPDATE item_mapping SET state = 'retired', retired_revision = ?1, retired_reason = ?2, updated_at = ?3 WHERE mapping_id = ?4", + params![revision as i64, reason.as_str(), at, mapping_id], + )?; + Ok(()) +} + +/// Retire every active mapping of a (character, realm) pair. +fn retire_all(tx: &Transaction<'_>, id: CharacterId, server_id: &str, reason: RetireReason, revision: u64) -> Result { + Ok(tx.execute( + "UPDATE item_mapping SET state = 'retired', retired_revision = ?1, retired_reason = ?2, updated_at = ?3 + WHERE character_id = ?4 AND server_id = ?5 AND state = 'active'", + params![revision as i64, reason.as_str(), now(), id.to_string(), server_id], + )?) +} + +fn read_item_mappings(conn: &Connection, id: CharacterId, server_id: &str, include_retired: bool) -> Result> { + let sql = format!( + "SELECT portable_item_id, local_item_guid, entry, identity, state, created_revision, confirmed_revision, retired_revision, retired_reason + FROM item_mapping WHERE character_id = ?1 AND server_id = ?2 {} ORDER BY mapping_id", + if include_retired { "" } else { "AND state = 'active'" } + ); + let mut stmt = conn.prepare(&sql)?; + let rows = stmt.query_map(params![id.to_string(), server_id], |r| { + Ok(( + r.get::<_, String>(0)?, + r.get::<_, i64>(1)?, + r.get::<_, String>(2)?, + r.get::<_, String>(3)?, + r.get::<_, String>(4)?, + r.get::<_, i64>(5)?, + r.get::<_, i64>(6)?, + r.get::<_, Option>(7)?, + r.get::<_, Option>(8)?, + )) + })?; + let mut out = Vec::new(); + for row in rows { + let (item, guid, entry, identity, state, created, confirmed, retired, reason) = row?; + out.push(ItemMapping { + portable_item_id: item.parse()?, + local_item_guid: guid as u32, + entry, + identity, + active: state == "active", + created_revision: created as u64, + confirmed_revision: confirmed as u64, + retired_revision: retired.map(|r| r as u64), + retired_reason: reason.as_deref().map(RetireReason::parse).transpose()?, + }); + } + Ok(out) +} + +fn create_in_tx(tx: &Transaction<'_>, profile: ProfileId, model: &PortableCharacter, encoded: &EncodedSnapshot, source_server_id: &str) -> Result<()> { + let id = model.character_id; + let exists: bool = tx.query_row("SELECT EXISTS(SELECT 1 FROM character WHERE character_id = ?1)", [id.to_string()], |r| r.get(0))?; + if exists { + return Err(PortableError::DuplicateCharacter(id)); + } + let profile_exists: bool = tx.query_row("SELECT EXISTS(SELECT 1 FROM profile WHERE profile_id = ?1)", [profile.to_string()], |r| r.get(0))?; + if !profile_exists { + return Err(PortableError::Invalid(format!("profile {profile} does not exist"))); + } + let at = now(); + tx.execute( + "INSERT INTO character(character_id, profile_id, ruleset, name, race, class, gender, level, revision, created_at, updated_at, archived) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, 1, ?9, ?9, 0)", + params![ + id.to_string(), + profile.to_string(), + model.ruleset.as_str(), + model.identity.name, + model.identity.race.to_string(), + model.identity.class.to_string(), + model.identity.gender, + model.progression.level, + at + ], + )?; + insert_snapshot(tx, id, 1, encoded, source_server_id, Some("created"), &at)?; + Ok(()) +} + +fn bind_in_tx(tx: &Transaction<'_>, id: CharacterId, server_id: &str, local_guid: u32, last_revision: u64, state: MappingState) -> Result<()> { + let record = read_character(tx, id)?; + if last_revision > record.revision { + return Err(PortableError::Invalid(format!("revision {last_revision} is newer than the canonical revision {}", record.revision))); + } + let holder: Option = tx + .query_row("SELECT character_id FROM character_server_mapping WHERE server_id = ?1 AND local_guid = ?2", params![server_id, local_guid], |r| r.get(0)) + .optional()?; + if holder.is_some_and(|h| h != id.to_string()) { + return Err(PortableError::LocalGuidTaken { server_id: server_id.to_string(), local_guid }); + } + let previous: Option = tx + .query_row("SELECT local_guid FROM character_server_mapping WHERE character_id = ?1 AND server_id = ?2", params![id.to_string(), server_id], |r| r.get(0)) + .optional()?; + if previous.is_some_and(|p| p != local_guid as i64) { + retire_all(tx, id, server_id, RetireReason::CharacterRebound, last_revision)?; + } + tx.execute( + "INSERT INTO character_server_mapping(character_id, server_id, local_guid, last_revision, state, updated_at) + VALUES (?1, ?2, ?3, ?4, ?5, ?6) + ON CONFLICT(character_id, server_id) DO UPDATE SET local_guid = excluded.local_guid, last_revision = excluded.last_revision, + state = excluded.state, updated_at = excluded.updated_at", + params![id.to_string(), server_id, local_guid, last_revision as i64, state.as_str(), now()], + )?; + Ok(()) +} + +fn reconcile_in_tx(tx: &Transaction<'_>, id: CharacterId, server_id: &str, revision: u64, observations: &[ItemObservation]) -> Result { + validate_observations(server_id, observations)?; + let record = read_character(tx, id)?; + if revision > record.revision { + return Err(PortableError::Invalid(format!("revision {revision} is newer than the canonical revision {}", record.revision))); + } + let bound: bool = tx.query_row( + "SELECT EXISTS(SELECT 1 FROM character_server_mapping WHERE character_id = ?1 AND server_id = ?2)", + params![id.to_string(), server_id], + |r| r.get(0), + )?; + if !bound { + return Err(PortableError::Invalid(format!("character {id} is not bound to server {server_id}"))); + } + + let mut report = ReconcileReport::default(); + let at = now(); + for o in observations { + let by_guid = active_by_guid(tx, id, server_id, o.local_item_guid)?; + if let Some(existing) = &by_guid { + if existing.portable_item_id == o.portable_item_id && existing.identity == o.identity { + tx.execute("UPDATE item_mapping SET confirmed_revision = ?1, updated_at = ?2 WHERE mapping_id = ?3", params![revision as i64, at, existing.mapping_id])?; + report.confirmed += 1; + continue; + } + } + if let Some(old) = by_guid { + retire_one(tx, old.mapping_id, RetireReason::GuidReused, revision, &at)?; + report.guid_reused += 1; + } + if let Some(old) = active_by_item(tx, id, server_id, o.portable_item_id)? { + retire_one(tx, old.mapping_id, RetireReason::Moved, revision, &at)?; + report.moved += 1; + } + tx.execute( + "INSERT INTO item_mapping(character_id, server_id, portable_item_id, local_item_guid, entry, identity, state, + created_revision, confirmed_revision, created_at, updated_at) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, 'active', ?7, ?7, ?8, ?8)", + params![id.to_string(), server_id, o.portable_item_id.to_string(), o.local_item_guid, o.entry.to_string(), o.identity, revision as i64, at], + )?; + report.added += 1; + } + // what is no longer on the character + let mut stmt = tx.prepare("SELECT mapping_id, portable_item_id FROM item_mapping WHERE character_id = ?1 AND server_id = ?2 AND state = 'active'")?; + let active: Vec<(i64, String)> = stmt.query_map(params![id.to_string(), server_id], |r| Ok((r.get(0)?, r.get(1)?)))?.collect::>()?; + drop(stmt); + for (mapping_id, item) in active { + if !observations.iter().any(|o| o.portable_item_id.to_string() == item) { + retire_one(tx, mapping_id, RetireReason::Absent, revision, &at)?; + report.absent += 1; + } + } + Ok(report) +} + +fn validate_observations(server_id: &str, observations: &[ItemObservation]) -> Result<()> { + let mut portable = std::collections::HashSet::new(); + let mut local = std::collections::HashSet::new(); + for o in observations { + if !portable.insert(o.portable_item_id) { + return Err(PortableError::Invalid(format!("portable item {} is observed twice", o.portable_item_id))); + } + if !local.insert(o.local_item_guid) { + return Err(PortableError::ItemGuidConflict { server_id: server_id.to_string(), local_item_guid: o.local_item_guid }); + } + if o.identity.is_empty() { + return Err(PortableError::Invalid("an observed item needs a content identity".into())); + } + } + Ok(()) +} + #[cfg(test)] mod tests; diff --git a/crates/coa-core/src/portable/store/tests.rs b/crates/coa-core/src/portable/store/tests.rs index a127893..a6fed9c 100644 --- a/crates/coa-core/src/portable/store/tests.rs +++ b/crates/coa-core/src/portable/store/tests.rs @@ -349,44 +349,169 @@ fn mapping_unique_constraints() { assert!(matches!(store.bind_server(CharacterId::new(), "realm-a", 1, 1, MappingState::Pending), Err(PortableError::UnknownCharacter(_)))); } -#[test] -fn item_mapping_unique_per_character_and_server() { +fn obs(item: PortableItemId, guid: u32, entry: u64, identity: &str) -> ItemObservation { + ItemObservation { portable_item_id: item, local_item_guid: guid, entry: ContentId::new("coa", "item", entry).unwrap(), identity: identity.to_string() } +} + +/// A character bound to `realm-a` with three portable items to play with. +fn bound() -> (Store, CharacterId, [PortableItemId; 3]) { let (mut store, profile) = fresh(); let id = created(&mut store, profile); + store.bind_server(id, "realm-a", 154, 1, MappingState::Active).unwrap(); let model = store.load_current(id).unwrap(); - let items: Vec = model.items.iter().take(4).map(|i| i.id).collect(); + let items = [model.items[0].id, model.items[1].id, model.items[2].id]; + (store, id, items) +} + +#[test] +fn item_mapping_needs_a_binding_and_enforces_uniqueness_among_active_rows() { + let (mut store, profile) = fresh(); + let id = created(&mut store, profile); + let items: Vec = store.load_current(id).unwrap().items.iter().take(4).map(|i| i.id).collect(); // an item mapping needs a server binding first - assert!(store.set_item_mappings(id, "realm-a", &[(items[0], 1)]).is_err()); + assert!(store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 1, 10, "v1:a")]).is_err()); store.bind_server(id, "realm-a", 154, 1, MappingState::Active).unwrap(); - store.set_item_mappings(id, "realm-a", &[(items[0], 9001), (items[1], 9002), (items[2], 9003)]).unwrap(); - assert_eq!(store.item_mappings(id, "realm-a").unwrap(), vec![(items[0], 9001), (items[1], 9002), (items[2], 9003)]); + let report = store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 9001, 10, "v1:a"), obs(items[1], 9002, 11, "v1:b"), obs(items[2], 9003, 12, "v1:c")]).unwrap(); + assert_eq!(report, ReconcileReport { added: 3, ..Default::default() }); + let active = store.item_mappings(id, "realm-a").unwrap(); + assert_eq!(active.iter().map(|m| (m.portable_item_id, m.local_item_guid)).collect::>(), vec![(items[0], 9001), (items[1], 9002), (items[2], 9003)]); + assert!(active.iter().all(|m| m.active && m.created_revision == 1 && m.entry.starts_with("coa:item:"))); - // UNIQUE(character_id, server_id, local_item_guid): one local item guid cannot stand for two portable items - let clash = store.set_item_mappings(id, "realm-a", &[(items[0], 9001), (items[1], 9001)]); + // input that maps one local guid twice, or one portable item twice, is refused before anything changes + let clash = store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 9001, 10, "v1:a"), obs(items[1], 9001, 11, "v1:b")]); assert!(matches!(clash, Err(PortableError::ItemGuidConflict { local_item_guid: 9001, .. })), "{clash:?}"); - // and the same portable item cannot have two local guids - assert!(store.set_item_mappings(id, "realm-a", &[(items[0], 1), (items[0], 2)]).is_err()); - // a failed replacement leaves the previous mappings intact + assert!(store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 1, 10, "v1:a"), obs(items[0], 2, 10, "v1:a")]).is_err()); + assert!(store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 1, 10, "")]).is_err(), "an observation without an identity is useless"); + assert!(store.reconcile_item_mappings(id, "realm-a", 9, &[]).is_err(), "revision from the future"); assert_eq!(store.item_mappings(id, "realm-a").unwrap().len(), 3); - // the database itself enforces the same rule, not just the Rust check + // the database itself enforces UNIQUE(character_id, server_id, local_item_guid) for active rows let direct = store.conn.execute( - "INSERT INTO item_mapping(character_id, server_id, portable_item_id, local_item_guid) VALUES (?1, 'realm-a', ?2, 9001)", + "INSERT INTO item_mapping(character_id, server_id, portable_item_id, local_item_guid, entry, identity, state, created_revision, confirmed_revision, created_at, updated_at) + VALUES (?1, 'realm-a', ?2, 9001, 'x', 'x', 'active', 1, 1, 'x', 'x')", params![id.to_string(), items[3].to_string()], ); - assert!(direct.is_err(), "UNIQUE(character_id, server_id, local_item_guid)"); + assert!(direct.is_err()); - // the same local item guid on another realm is fine + // the same local item guid on another realm is another item store.bind_server(id, "realm-b", 8421, 1, MappingState::Active).unwrap(); - store.set_item_mappings(id, "realm-b", &[(items[0], 9001)]).unwrap(); - assert_eq!(store.item_mappings(id, "realm-b").unwrap(), vec![(items[0], 9001)]); + store.reconcile_item_mappings(id, "realm-b", 1, &[obs(items[0], 9001, 10, "v1:a")]).unwrap(); + assert_eq!(store.item_mappings(id, "realm-b").unwrap().len(), 1); +} - // if the local character changes (deleted and imported again), the old item guids are meaningless +#[test] +fn a_recycled_local_guid_is_not_the_old_item() { + let (mut store, id, items) = bound(); + store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 5000, 10, "v1:sword")]).unwrap(); + + // later the sword is destroyed; the realm gives guid 5000 to a different item with another identity + let resolutions = store.resolve_item_ids(id, "realm-a", &[(5000, "v1:potion"), (5000, "v1:sword"), (5001, "v1:sword")]).unwrap(); + assert_eq!(resolutions, vec![ItemResolution::Reused { previous: items[0] }, ItemResolution::Known(items[0]), ItemResolution::Unmapped]); + + // the new item gets a new portable id; the old mapping is retired, not overwritten + let fresh_item = PortableItemId::new(); + let report = store.reconcile_item_mappings(id, "realm-a", 1, &[obs(fresh_item, 5000, 77, "v1:potion")]).unwrap(); + assert_eq!((report.guid_reused, report.added, report.absent), (1, 1, 0)); + + let active = store.item_mappings(id, "realm-a").unwrap(); + assert_eq!(active.len(), 1); + assert_eq!((active[0].portable_item_id, active[0].local_item_guid), (fresh_item, 5000)); + let history = store.item_mapping_history(id, "realm-a").unwrap(); + assert_eq!(history.len(), 2); + assert!(!history[0].active); + assert_eq!(history[0].portable_item_id, items[0]); + assert_eq!(history[0].retired_reason, Some(RetireReason::GuidReused)); + assert_eq!(history[0].retired_revision, Some(1)); + + // the old portable item is not resurrected by the recycled guid + assert_eq!(store.resolve_item_ids(id, "realm-a", &[(5000, "v1:sword")]).unwrap(), vec![ItemResolution::Reused { previous: fresh_item }]); +} + +#[test] +fn the_same_portable_id_with_a_changed_identity_is_treated_as_reuse_too() { + let (mut store, id, items) = bound(); + store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 5000, 10, "v1:old")]).unwrap(); + let report = store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 5000, 10, "v1:new")]).unwrap(); + assert_eq!((report.confirmed, report.guid_reused, report.added), (0, 1, 1)); + let history = store.item_mapping_history(id, "realm-a").unwrap(); + assert_eq!((history.iter().filter(|m| m.active).count(), history.len()), (1, 2)); +} + +#[test] +fn moved_and_absent_items_are_retired_with_their_reason() { + let (mut store, id, items) = bound(); + store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 100, 1, "v1:a"), obs(items[1], 101, 2, "v1:b"), obs(items[2], 102, 3, "v1:c")]).unwrap(); + + // item 0 got a new local guid (re-imported), item 1 is gone, item 2 is unchanged + let report = store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 200, 1, "v1:a"), obs(items[2], 102, 3, "v1:c")]).unwrap(); + assert_eq!(report, ReconcileReport { confirmed: 1, added: 1, guid_reused: 0, moved: 1, absent: 1 }); + + let active: Vec<(PortableItemId, u32)> = store.item_mappings(id, "realm-a").unwrap().into_iter().map(|m| (m.portable_item_id, m.local_item_guid)).collect(); + assert_eq!(active, vec![(items[2], 102), (items[0], 200)]); + let reasons: Vec> = store.item_mapping_history(id, "realm-a").unwrap().into_iter().filter(|m| !m.active).map(|m| m.retired_reason).collect(); + assert_eq!(reasons.len(), 2); + assert!(reasons.contains(&Some(RetireReason::Moved)) && reasons.contains(&Some(RetireReason::Absent))); +} + +#[test] +fn rebinding_to_another_local_character_retires_its_item_mappings() { + let (mut store, id, items) = bound(); + store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 100, 1, "v1:a")]).unwrap(); store.bind_server(id, "realm-a", 777, 1, MappingState::Active).unwrap(); assert!(store.item_mappings(id, "realm-a").unwrap().is_empty()); - assert_eq!(store.item_mappings(id, "realm-b").unwrap().len(), 1, "other realms are untouched"); + let history = store.item_mapping_history(id, "realm-a").unwrap(); + assert_eq!(history.len(), 1); + assert_eq!(history[0].retired_reason, Some(RetireReason::CharacterRebound)); + // binding again to the same local guid changes nothing + store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 300, 1, "v1:a")]).unwrap(); + store.bind_server(id, "realm-a", 777, 1, MappingState::Synced).unwrap(); + assert_eq!(store.item_mappings(id, "realm-a").unwrap().len(), 1); +} + +#[test] +fn a_failed_reconcile_leaves_the_mappings_untouched() { + let (mut store, id, items) = bound(); + store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 100, 1, "v1:a"), obs(items[1], 101, 2, "v1:b")]).unwrap(); + let before = store.item_mapping_history(id, "realm-a").unwrap(); + assert!(store.reconcile_item_mappings(id, "realm-a", 1, &[obs(items[0], 100, 1, "v1:a"), obs(items[0], 5, 1, "v1:a")]).is_err()); + assert_eq!(store.item_mapping_history(id, "realm-a").unwrap(), before); +} + +#[test] +fn schema_1_item_mappings_survive_the_migration_as_unverified() { + let dir = tempfile::tempdir().unwrap(); + let file = Store::path_of(dir.path()); + let (character, item); + { + // build a schema-1 database by hand, exactly as Phase 1 wrote it + let mut store = Store::open_file(&file).unwrap(); + let profile = store.default_profile().unwrap(); + character = created(&mut store, profile); + item = store.load_current(character).unwrap().items[0].id; + store.bind_server(character, "realm-a", 154, 1, MappingState::Active).unwrap(); + store.conn.execute_batch( + "DROP TABLE item_mapping; + CREATE TABLE item_mapping (character_id TEXT NOT NULL, server_id TEXT NOT NULL, portable_item_id TEXT NOT NULL, local_item_guid INTEGER NOT NULL, + PRIMARY KEY (character_id, server_id, portable_item_id), UNIQUE (character_id, server_id, local_item_guid), + FOREIGN KEY (character_id, server_id) REFERENCES character_server_mapping(character_id, server_id) ON DELETE CASCADE) STRICT; + PRAGMA user_version = 1;", + ) + .unwrap(); + store.conn.execute( + "INSERT INTO item_mapping VALUES (?1, 'realm-a', ?2, 4242)", + params![character.to_string(), item.to_string()], + ) + .unwrap(); + } + let store = Store::open_file(&file).unwrap(); + assert_eq!(store.schema_version().unwrap(), 2); + let mappings = store.item_mappings(character, "realm-a").unwrap(); + assert_eq!(mappings.len(), 1); + assert_eq!((mappings[0].portable_item_id, mappings[0].local_item_guid, mappings[0].identity.as_str()), (item, 4242, "")); + // an unverified mapping never matches a real identity, so it is treated as a recycled guid, not trusted + assert_eq!(store.resolve_item_ids(character, "realm-a", &[(4242, "v1:real")]).unwrap(), vec![ItemResolution::Reused { previous: item }]); } #[test] diff --git a/docs/PORTABLE_EXPORT.md b/docs/PORTABLE_EXPORT.md new file mode 100644 index 0000000..34390a5 --- /dev/null +++ b/docs/PORTABLE_EXPORT.md @@ -0,0 +1,96 @@ +# Portable export from a realm (Phase 2) + +Code: `crates/coa-core/src/portable/realm/`. Scope decisions: `PORTABLE_CHARACTERS_AUDIT.md` sections 15-16. + +Phase 2 is **read-only**. It reads one **offline** character out of a realm's characters database into a +`PortableCharacter` and (for "Make Portable") registers it in the local store. It never writes to a realm. + +## What it does + +| Function | Meaning | +|---|---| +| `inspect_characters(db)` | "Inspect realm characters": every character of a non-bot account with the reasons it cannot be exported yet | +| `export_character(db, guid, character_id, prior_items)` | "Export snapshot": the portable model + item observations + warnings | +| `make_portable(db, store, profile, server_id, guid)` | "Make Portable": export, then register in the local store in one transaction (revision 1, bound to the realm, items mapped) | + +No Tauri command or UI exists yet (Phase 9). + +## How the realm is read + +* Through the Manager's existing `Db` abstraction (the bundled `mysql` client, or the same client inside a Docker + database container). No driver, no new connection type, no published port. The Wildcard realm profile is routed by + `Db` exactly like everything else, and **the database decides the ruleset**, not the caller. +* **Fixed SQL, typed input.** Every statement is a literal in `script.rs`. The only input is the character's local + guid as a `u32` formatted as a number. Table and column names of *unknown* tables come from `information_schema`, + are checked as plain identifiers and appear only in `SELECT COUNT(*)`. +* **One consistent read-only snapshot.** All statements for a character run in one `mysql` session inside + `SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY;`. + Verified against a real server: a write inside the script fails, and a concurrent write by someone else in the + middle of the script is not seen. +* **Hex-encoded text.** Names, item texts, settings and macro blobs are returned as `x`, so tabs, newlines, quotes + and backslashes cannot confuse the parser. +* Writing into a realm (Phase 3) must use prepared statements or the realm's own in-core import; this read path is not + a basis for it. + +## Who may be exported (`Blocker`) + +| Blocker | Rule | +|---|---| +| `Online` | `characters.online <> 0` (also after a crash, when the flag is stale: stop the realm or log in/out) | +| `Deleted` | `deleteDate` is set | +| `BotAccount` | account `COABOT*` or `COAMANAGER` | +| `ActiveChallenge` | a row in `coa_character_challenge` | +| `ActiveGameMode` | `coa_character_gamemode.gameMode <> 0` | +| `ActiveCustomTrial` | a row in `coa_custom_trial_active` | +| `PendingManastormCaches` | a row in `ascension_manastorm_cache` (it names item guids that would be orphaned) | +| `UnclassifiedState(table)` | a table this Manager does not know has a per-character column with rows for this character | + +Finished challenges, game mode 0 and condition flags are history, not active state, and do not block (decision D6: +*active* state blocks). A realm that lacks a core table (`SchemaMismatch`) cannot be exported from. + +## What is exported (v1) + +17 tables: `characters`, `character_inventory`, `item_instance`, `character_gifts`, `character_spell`, +`character_talent`, `character_skills`, `character_glyphs`, `character_reputation`, `character_queststatus`, +`character_queststatus_rewarded` (`active = 1`, as the realm loads it), `character_action`, `character_pet`, `pet_spell`, +`character_pet_declinedname`, `character_settings` (by policy), `character_account_data` (macros, type 5). + +**Not exported by decision** (deferred): collections, the personal Ascension bank, equipment sets, per-character wardrobe +(`character_appearance*`), `mod_craftsmans_codex`. Auras, cooldowns, mail, guild, social, achievements, daily/weekly +quests, position and homebind are never part of v1. + +Left out *with a warning* (the realm would delete them on load anyway): inventory rows without an `item_instance`, +items in a bag that is not on the character, items in buyback slots. + +### `character_settings` policy (`policy.rs`, version 1) + +* **Carry**: known CoA gameplay state (`core.ascension_*`, `core.spell_charge.*`, `core.destiny_weaver`, ...), and + `core.wildcard*` on a Wildcard realm. +* **Drop**: `coa.bot*`, `coa.gameplay_test`, `coa.highrisk`. +* **Quarantine**: everything else is kept in the snapshot as the opaque extension `coa:unlisted-settings` (never + destroyed, never applied at a realm). + +### Table registry (`registry.rs`) + +All 163 tables of the characters schema are classified (`Portable`, `Deferred`, `Collection`, `AccountLocal`, +`CharacterLocal`, `Blocking`, `Realm`). A test fails if the real schema has a table the registry does not know, and at +export time an unknown table that holds this character's rows blocks the export. A silent half-export is not possible. + +## Item identity + +Realms recycle local item guids. `ItemObservation.identity` hashes what cannot change during an item's life (entry, +random property, crafter). A re-export keeps an item's portable id only if the identity behind the local guid is +unchanged; a recycled guid produces a new portable item. The store side is in `PORTABLE_FORMAT.md` (item mapping +lifecycle). + +## Tests + +* `realm/tests.rs`: on **recorded answers of a real MySQL** (`testdata/golden/`), no database needed: naked level 1, + geared level 80 (bags, enchants, gems, random suffix, crafted-by, texts, charges, gift, currency tokens), quests, + reputation, action bars, 300 spells + talents + glyphs + skills + CoA settings + binary macros, hunter and summon + pets with declined names, every blocker, item id stability and recycling, Wildcard ruleset, CRLF, 400 damaged + answers (no panics), registration in the store (one transaction, refused twice, rolled back on failure). +* `realm/live.rs` (`#[ignore]`): the same answers re-recorded/verified against a **real disposable MySQL**, plus the + read-only and snapshot-consistency proofs, the 21 genuine template characters of the schema fixture, and the proof that + `make_portable` changes nothing in the realm. Instructions are at the top of the file. +* `tools/gen_portable_fixture.py` writes `testdata/realm-fixture.sql` (deterministic). diff --git a/docs/PORTABLE_FORMAT.md b/docs/PORTABLE_FORMAT.md index 75c4aee..a83f650 100644 --- a/docs/PORTABLE_FORMAT.md +++ b/docs/PORTABLE_FORMAT.md @@ -76,7 +76,7 @@ Account-wide sets of numeric ids (`coa:wardrobe`, `coa:vanity`, ...), stored per ## Store (`%LOCALAPPDATA%\CoAServerManager\portable\portable.db`) SQLite, WAL, `synchronous=FULL`, `foreign_keys=ON`, `application_id = 0x434F4150`, forward-only migrations tracked in -`PRAGMA user_version`. A database from a newer Manager, or a foreign SQLite file, is refused and left untouched. +`PRAGMA user_version` (currently 2). A database from a newer Manager, or a foreign SQLite file, is refused and left untouched. | Table | Purpose | |---|---| @@ -84,8 +84,27 @@ SQLite, WAL, `synchronous=FULL`, `foreign_keys=ON`, `application_id = 0x434F4150 | `character` | summary row + canonical revision | | `snapshot` | `(character_id, revision)` -> compressed canonical payload + hash | | `character_server_mapping` | `(character_id, server_id)` -> local guid; `UNIQUE(server_id, local_guid)` | -| `item_mapping` | `(character_id, server_id, portable_item_id)` -> local item guid; `UNIQUE(character_id, server_id, local_item_guid)` | +| `item_mapping` | one row per mapping with a lifecycle (schema 2, see below) | | `collection` | per profile and kind: revision, hash, encoded set | | `setting` | `history_keep` | -The store never reads or writes a realm database and never leaves the machine. +## Item mapping lifecycle (schema 2) + +A realm's item guid counter restarts at `MAX(guid)+1`, so a freed guid can be given to a different item. A bare +`guid -> portable item` mapping would attach the new item to the old portable id. Every mapping therefore records what +the item *was* (`entry`, `identity`) and has a state: + +* `active`: at most one per portable item and at most one per local item guid + (`UNIQUE(character_id, server_id, local_item_guid)` and `UNIQUE(.., portable_item_id)`, both for active rows); +* `retired` (kept for the record) with a reason: `guid_reused`, `moved`, `absent`, `character_rebound`. + +`Store::reconcile_item_mappings` takes the complete observation of a character on a realm and confirms, adds or retires +mappings; `Store::resolve_item_ids` answers `Known`, `Reused` (recycled guid) or `Unmapped` for a local guid and its +current identity. Schema-1 rows are migrated with an empty identity, which matches nothing: they are re-verified, never +trusted. Rebinding a portable character to another local guid retires its item mappings. + +The identity covers what cannot change during an item's life (entry, random property, crafter); two different items that +share all of these are interchangeable for mapping purposes. + +The store never reads or writes a realm database and never leaves the machine. (Phase 2's realm reader lives in +`portable/realm/` and is documented in `PORTABLE_EXPORT.md`; it only reads.) diff --git a/tools/gen_portable_fixture.py b/tools/gen_portable_fixture.py new file mode 100644 index 0000000..47fb233 --- /dev/null +++ b/tools/gen_portable_fixture.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python3 +"""Generate the disposable realm fixture used by the Phase 2 exporter tests. + + python tools/gen_portable_fixture.py > crates/coa-core/src/portable/realm/testdata/realm-fixture.sql + +The SQL is applied to an *empty* CoA characters/auth schema of a throw-away MySQL (never to a real realm). It creates +synthetic characters that cover what the exporter has to understand; the recorded answers of the exporter against this +data live next to it in `testdata/golden/`. Text is written as hex literals so no escaping can go wrong. +""" + +import binascii +import random + +rng = random.Random(20261006) # deterministic +out = [] + + +def add(sql): + out.append(sql.rstrip(";") + ";") + + +def hx(b): + return "0x" + binascii.hexlify(b).decode() + + +def T(s): + """A text literal (utf8mb4) as a hex literal.""" + return "_utf8mb4 " + hx(s.encode("utf8")) if s else "''" + + +def B(b): + return hx(b) if b else "''" + + +def insert(table, cols, rows): + if not rows: + return + values = ",\n ".join("(" + ", ".join(str(v) for v in row) + ")" for row in rows) + add(f"INSERT INTO acore_characters.`{table}` ({', '.join('`' + c + '`' for c in cols)}) VALUES\n {values}") + + +COLS = ["guid", "account", "name", "race", "class", "gender", "level", "xp", "money", "skin", "face", "hairStyle", "hairColor", + "facialStyle", "bankSlots", "playerFlags", "taximask", "online", "arenaPoints", "totalHonorPoints", "todayHonorPoints", + "yesterdayHonorPoints", "totalKills", "todayKills", "yesterdayKills", "chosenTitle", "knownCurrencies", "watchedFaction", + "talentGroupsCount", "activeTalentGroup", "exploredZones", "knownTitles", "actionBars", "extraBonusTalentCount", + "resettalents_cost", "stable_slots", "innTriggerId", "deleteDate"] + + +def character(guid, account, name, race=1, cls=12, gender=0, level=1, **kw): + d = dict(xp=0, money=0, skin=1, face=2, hair=3, haircolor=4, facial=0, bank=0, flags=0, taxi="0 0 0 0 ", online=0, arena=0, + honor=0, today_honor=0, yday_honor=0, kills=0, today_kills=0, yday_kills=0, title=0, currencies=0, watched=0, + groups=1, active=0, explored="0 0 0 0 ", titles="0 0 0 0 0 0 ", bars=0, extra=0, reset=0, stable=0, deleted="NULL") + d.update(kw) + insert("characters", COLS, [[guid, account, T(name), race, cls, gender, level, d["xp"], d["money"], d["skin"], d["face"], d["hair"], + d["haircolor"], d["facial"], d["bank"], d["flags"], T(d["taxi"]), d["online"], d["arena"], d["honor"], + d["today_honor"], d["yday_honor"], d["kills"], d["today_kills"], d["yday_kills"], d["title"], + d["currencies"], d["watched"], d["groups"], d["active"], T(d["explored"]), T(d["titles"]), d["bars"], + d["extra"], d["reset"], d["stable"], 0, d["deleted"]]]) + + +# ---- auth accounts ------------------------------------------------------------------------------------------------- +for aid, user in [(5001, "PLAYER1"), (5002, "COABOTHOST1"), (5003, "PLAYER3")]: + add(f"INSERT INTO acore_auth.account (id, username, salt, verifier) VALUES ({aid}, '{user}', UNHEX(REPEAT('11',32)), UNHEX(REPEAT('22',32)))") + +add("CREATE TABLE IF NOT EXISTS acore_characters.mod_unknown_state (guid INT UNSIGNED NOT NULL, note VARCHAR(32) NOT NULL, PRIMARY KEY (guid))") + +# ---- 1001 naked level 1 --------------------------------------------------------------------------------------------- +character(1001, 5001, "Naked") + +# ---- 1002 geared level 80: equipment, bags, enchants, gems, texts, charges, gift, orphans --------------------------------- +explored = " ".join(str((i * 7919) % 100003) for i in range(128)) + " " +character(1002, 5001, "Geared", race=2, cls=21, gender=1, level=80, xp=12345, money=200060523, bank=4, flags=0x0404, arena=150, + honor=4092, today_honor=10, yday_honor=20, kills=777, today_kills=3, yday_kills=4, title=5, currencies=165, watched=72, + explored=explored, titles="1 0 0 0 0 0 ", bars=15, extra=2, reset=100000, stable=2) +inst_cols = ["guid", "itemEntry", "owner_guid", "creatorGuid", "giftCreatorGuid", "count", "duration", "charges", "flags", "enchantments", + "randomPropertyId", "durability", "playedTime", "text"] +inv_cols = ["guid", "bag", "slot", "item"] + + +def enchants(**slots): + toks = [[0, 0, 0] for _ in range(12)] + for k, v in slots.items(): + toks[int(k[1:])] = list(v) + return " ".join(str(x) for t in toks for x in t) + " " + + +insts, invs = [], [] +g = 20000 + + +def item(entry, bag, slot, count=1, flags=1, ench=None, rand=0, dur=100, creator=0, charges="0 0 0 0 0 ", text="NULL", duration=0, played=3600): + global g + g += 1 + insts.append([g, entry, 1002, creator, 0, count, duration, "NULL" if charges is None else T(charges), flags, T(ench or enchants()), rand, dur, played, + text if text == "NULL" else T(text)]) + invs.append([1002, bag, slot, g]) + return g + + +equipment = [] +for slot in range(19): + kw = {} + if slot % 3 == 0: + kw = dict(e0=(3000 + slot, 0, 0), e2=(3878, 0, 0), e3=(3879, 0, 0), e4=(3880, 0, 0)) + equipment.append(item(30000 + slot * 17, 0, slot, ench=enchants(**kw) if kw else None, rand=-57 if slot == 5 else 0, + dur=90 + slot, creator=1001 if slot == 4 else 0)) +bags = [item(41000 + b, 0, b, flags=1) for b in range(19, 23)] +for bi, bag_guid in enumerate(bags): + for s in range(6): + item(50000 + bi * 10 + s, bag_guid, s, count=1 + (s % 3) * 4, flags=0) +for s in range(23, 31): + item(60000 + s, 0, s, count=20, flags=0) +item(70001, 0, 39, text="A book.\nSecond line\twith a tab, a \"quote\", an 'apostrophe', a \\ backslash and 中文.") +item(70002, 0, 40, charges="-1 0 0 0 0 ", flags=0, count=5, duration=3600) +item(70003, 0, 41, charges=None, flags=0) +item(375250, 0, 118, count=12, flags=0) # currency token slot +wrapped = item(5042, 0, 42, flags=8) +# orphans the realm itself would clean up +invs.append([1002, 0, 50, 20999]) # inventory row without an item_instance +g += 1 +insts.append([29998, 70099, 1002, 0, 0, 1, 0, T("0 0 0 0 0 "), 0, T(enchants()), 0, 0, 0, "NULL"]) +invs.append([1002, 29999, 3, 29998]) # inside a bag that is not on the character +item(70004, 0, 80, flags=0) # buyback slot +insert("item_instance", inst_cols, insts) +insert("character_inventory", inv_cols, invs) +insert("character_gifts", ["guid", "item_guid", "entry", "flags"], [[1002, wrapped, 8000, 8]]) +insert("character_spell", ["guid", "spell", "specMask"], [[1002, 500000 + n * 3, 3 if n % 5 == 0 else 1] for n in range(1, 61)]) +insert("character_reputation", ["guid", "faction", "standing", "flags"], [[1002, f * 3, f * 100 - 3000, 17 if f % 7 == 0 else 1] for f in range(1, 21)]) +add("INSERT INTO acore_characters.character_homebind (guid, mapId, zoneId, posX, posY, posZ) VALUES (1002, 0, 12, 1.5, 2.5, 3.5)") +add("INSERT INTO acore_characters.character_aura (guid, casterGuid, itemGuid, spell, effectMask, recalculateMask, stackCount, maxDuration, remainTime, remainCharges) VALUES (1002, 1002, 0, 12345, 1, 0, 1, 60000, 30000, 0)") +add("INSERT INTO acore_characters.character_spell_cooldown (guid, spell, category, item, time, needSend) VALUES (1002, 500003, 0, 0, 1790000000, 0)") + +# ---- 1003 quests, reputation, action bars --------------------------------------------------------------------------------- +character(1003, 5001, "Questy", race=3, cls=13, level=40, xp=900, money=12345) +insert("character_queststatus", ["guid", "quest", "status", "explored", "timer", "mobcount1", "mobcount2", "mobcount3", "mobcount4", + "itemcount1", "itemcount2", "itemcount3", "itemcount4", "itemcount5", "itemcount6", "playercount"], + [[1003, 12001, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1003, 12002, 1, 1, 600, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0]]) +insert("character_queststatus_rewarded", ["guid", "quest", "active"], [[1003, 12000, 1], [1003, 12003, 1], [1003, 12004, 1], [1003, 12005, 0]]) +insert("character_queststatus_daily", ["guid", "quest", "time"], [[1003, 13000, 1790000000]]) +insert("character_reputation", ["guid", "faction", "standing", "flags"], [[1003, f, f * 50, 1] for f in range(1, 11)]) +insert("character_action", ["guid", "spec", "button", "action", "type"], + [[1003, 0, b, 500003 + b * 3, 0] for b in range(12)] + [[1003, 1, b, 500100 + b, 0] for b in range(4)] + [[1003, 1, 4, 7, 64]]) + +# ---- 1004 build: spells, talents, glyphs, skills, settings, macros ------------------------------------------------------------- +character(1004, 5001, "Дракон", race=8, cls=25, level=80, money=5000000, titles="0 0 0 0 0 0 ") +insert("character_spell", ["guid", "spell", "specMask"], [[1004, 500000 + n * 3, [1, 2, 3][n % 3]] for n in range(1, 301)]) +insert("character_talent", ["guid", "spell", "specMask"], [[1004, 900000 + n, 1] for n in range(1, 6)]) +insert("character_glyphs", ["guid", "talentGroup", "glyph1", "glyph2", "glyph3", "glyph4", "glyph5", "glyph6"], [[1004, 0, 1, 2, 3, 4, 5, 6], [1004, 1, 7, 0, 0, 0, 0, 0]]) +insert("character_skills", ["guid", "skill", "value", "max"], [[1004, 100 + n, 300 + n, 450] for n in range(10)]) +insert("character_settings", ["guid", "source", "data"], [ + [1004, T("core.ascension_active_spec"), T("54 ")], + [1004, T("core.ascension_starter"), T("1 ")], + [1004, T("core.ascension_build.54"), T("3 56710 56320 90101 ")], + [1004, T("core.ascension_bar.54"), T("2 0 500003 1 500006 ")], + [1004, T("core.ascension_slot.active"), T("0 ")], + [1004, T("core.spell_charge.804197"), T("2 1790000000 ")], + [1004, T("coa.bot.gear"), T("1 2 3 ")], + [1004, T("coa.gear_pref_weapon"), T("2 ")], + [1004, T("mod.example.new_feature"), T("9 8 7 ")], + [1004, T("core.wildcard.cards"), T("1 2 ")], +]) +macro_blob = bytes(rng.randrange(256) for _ in range(600)) + b"\x00\x01\xff end" +insert("character_account_data", ["guid", "type", "time", "data"], [[1004, 5, 1790000000, B(macro_blob)], [1004, 1, 1790000001, B(b"ignored config cache")]]) + +# ---- 1005 pets --------------------------------------------------------------------------------------------------------------- +character(1005, 5001, "Hunty", race=4, cls=14, level=60, stable=2) +pet_cols = ["id", "entry", "owner", "modelid", "CreatedBySpell", "PetType", "level", "exp", "Reactstate", "name", "renamed", "slot", + "curhealth", "curmana", "curhappiness", "savetime", "abdata"] +insert("character_pet", pet_cols, [ + [3001, 42, 1005, 901, 1515, 1, 60, 1000, 1, T("Rex"), 0, 0, 5000, 100, 1000000, 1790000000, T("7 2 0 0 1 0 1 1 0 ")], + [3002, 43, 1005, 902, 1515, 1, 55, 200, 1, T("Fang"), 1, 1, 4000, 90, 900000, 1790000000, T("7 2 ")], + [3003, 416, 1005, 4449, 688, 0, 60, 0, 1, T("Imp"), 0, 100, 3000, 400, 0, 1790000000, "NULL"], +]) +insert("pet_spell", ["guid", "spell", "active"], [[3001, s, a] for s, a in [(17253, 1), (16827, 0), (24604, 1), (61683, 0), (34889, 1), (50256, 0)]] + [[3003, 3110, 1]]) +insert("character_pet_declinedname", ["id", "owner", "genitive", "dative", "accusative", "instrumental", "prepositional"], + [[3002, 1005, T("Фанга"), T("Фангу"), T("Фанг"), T("Фангом"), T("Фанге")]]) +add("INSERT INTO acore_characters.pet_aura (guid, casterGuid, spell, effectMask, recalculateMask, stackCount, maxDuration, remainTime, remainCharges) VALUES (3001, 1005, 99, 1, 0, 1, 1000, 500, 0)") + +# ---- blocked characters ------------------------------------------------------------------------------------------------------- +character(1006, 5001, "Online", level=10, online=1) +character(1007, 5001, "Hardcore", level=10) +add("INSERT INTO acore_characters.coa_character_gamemode (guid, gameMode) VALUES (1007, 1)") +add("INSERT INTO acore_characters.coa_character_challenge (guid, challengeId, level, deaths, hunger, thirst, startTime) VALUES (1007, 5, 1, 0, 90, 90, 1790000000)") +character(1008, 5001, "Cachey", level=30) +add("INSERT INTO acore_characters.item_instance (guid, itemEntry, owner_guid, enchantments) VALUES (30001, 900001, 1008, '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ')") +add("INSERT INTO acore_characters.ascension_manastorm_cache (item, guid) VALUES (30001, 1008)") +character(1009, 5001, "Deleted", level=20, deleted=1790000000) +character(1010, 5002, "Botty", level=80) +character(1011, 5003, "Moddy", level=50) +add("INSERT INTO acore_characters.mod_unknown_state (guid, note) VALUES (1011, 'data this Manager does not know')") + +# ---- characters that look like the blocked ones but are NOT blocked --------------------------------------------------------------- +character(1012, 5001, "History", level=60) +add("INSERT INTO acore_characters.coa_character_gamemode (guid, gameMode) VALUES (1012, 0)") +add("INSERT INTO acore_characters.coa_challenge_completion (guid, challengeId, level, completeTime, startTime) VALUES (1012, 5, 1, 1790000100, 1790000000)") +add("INSERT INTO acore_characters.coa_character_condition (guid, flag) VALUES (1012, 'finished_once')") + +print("-- generated by tools/gen_portable_fixture.py; applied to a disposable, empty characters + auth schema only") +print("\n".join(out))