definition.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include "../../../../middleware/datagen/family4/loadout/definition.h"
  6. #include "../../../../state/account/account_state.h"
  7. namespace sunrise::server::bap::encrypted::queuez {
  8. /** Family zero carries the banner anchor and the record for the character it names. */
  9. inline constexpr std::uint32_t kBannerFamilyType = 0;
  10. /** Family two carries the social roster the Roster and Fireteam panels draw. */
  11. inline constexpr std::uint32_t kSocialRosterFamilyType = 2;
  12. /** Family three carries the account character roster. */
  13. inline constexpr std::uint32_t kRosterFamilyType = 3;
  14. /** Family four carries account, character, and item state. */
  15. inline constexpr std::uint32_t kAccountFamilyType = 4;
  16. /** Initial and replayed full snapshots use version zero. */
  17. inline constexpr std::int32_t kInitialFamilyVersion = 0;
  18. /**
  19. * Family four holds account, character, one id per character-owned item, and one id per
  20. * resident-backed mod or shader stack. Profile currency rows carry no instance SOID; the fixed
  21. * addition covers all 50 native rows in each supported action-source bucket.
  22. */
  23. inline constexpr std::size_t kResidentCapacity =
  24. 2 + state::kCharacterCapacity * middleware::datagen::family4::loadout::kItemCapacity
  25. + state::account::inventory::kProfileActionSourceCapacity;
  26. /** Resident zero is the account object. The character object is found by its definition id. */
  27. /** When the roster is published after a change, as measured in the character-select flow. */
  28. enum class Family3Phase : std::uint8_t {
  29. normal,
  30. publishOnce,
  31. responseOnly,
  32. };
  33. /** Stable id of one object now resident in this peer's Family-4 store. */
  34. struct ResidentObject {
  35. std::uint64_t objectSoid{};
  36. std::uint32_t definitionId{};
  37. };
  38. /** Fixed queuez transaction state owned by one authenticated BAP peer. */
  39. struct SessionState {
  40. std::uint64_t family4RootSoid{};
  41. /** Root whose Family-3 roster store has accepted its full snapshot. */
  42. std::uint64_t family3RootSoid{};
  43. std::array<ResidentObject, kResidentCapacity> family4Residents{};
  44. /** Character the resident family-zero pair names. Only a change earns an incremental. */
  45. std::uint64_t family0Character{};
  46. std::int32_t family4Version{};
  47. /** Version zero is the full roster; every accepted appearance refresh adds exactly one. */
  48. std::int32_t family3Version{};
  49. /** Retail sets the full-snapshot flag once per family, then increments this by one. */
  50. std::int32_t family0Version{};
  51. std::uint16_t family4ResidentCount{};
  52. Family3Phase family3Phase{Family3Phase::normal};
  53. bool family4Active{};
  54. /** Set only after a complete Family-3 full-snapshot frame has been staged for publication. */
  55. bool family3Active{};
  56. /** Set once the family-zero full snapshot has been published to this peer. */
  57. bool family0Active{};
  58. /**
  59. * Root of a family-zero subscription that arrived before any character was selected.
  60. * The peer never asks again, so the held root is answered at the first pick. Zero once sent.
  61. */
  62. std::uint64_t pendingBannerRoot{};
  63. };
  64. /** Validated opcode-505 after-image and its resident account definition. */
  65. struct ChangeCharacter {
  66. SessionState after{};
  67. std::uint32_t accountDefinitionId{};
  68. };
  69. /**
  70. * Validated opcode-504 after-image and the three object operations its Family-4 move needs.
  71. * The character object is deleted at its old key before it is upserted at the new one. One slot
  72. * holds it, and an upsert onto a full slot raises queuez error 4.
  73. */
  74. struct SelectCharacter {
  75. SessionState after{};
  76. std::uint32_t accountDefinitionId{};
  77. std::uint32_t characterDefinitionId{};
  78. std::uint64_t previousCharacterSoid{};
  79. std::uint64_t selectedCharacterSoid{};
  80. /**
  81. * The account object moves as a selected-character patch, not a full body.
  82. * The first pick replaces it whole, which is the measured path. After opcode 505 a resent
  83. * account body wipes the resident settings block, so only the one field goes out.
  84. */
  85. bool patchAccount{};
  86. };
  87. /** Validated opcode-403 after-image for a single resident character upsert. */
  88. struct EquipmentSwap {
  89. SessionState after{};
  90. std::uint32_t characterDefinitionId{};
  91. std::uint64_t characterSoid{};
  92. };
  93. /**
  94. * Validated Family-0 after-image for the appearance record changed by one equipment swap.
  95. *
  96. * The resident character key does not move: the update upserts that one record in place.
  97. */
  98. struct CharacterAppearanceRefresh {
  99. SessionState after{};
  100. std::uint64_t characterSoid{};
  101. };
  102. /** Validated Family-3 appearance after-image for one character and optional account roster. */
  103. struct RosterAppearanceRefresh {
  104. SessionState after{};
  105. std::uint64_t characterSoid{};
  106. /** Equipment moves change the roster's slot definition; socket-only changes do not. */
  107. bool includeRoster{};
  108. };
  109. /** Validated item-acquisition after-image for one character upsert and one new instance object. */
  110. struct ItemAcquisition {
  111. SessionState after{};
  112. std::uint32_t accountDefinitionId{};
  113. std::uint32_t characterDefinitionId{};
  114. std::uint32_t itemInstanceDefinitionId{};
  115. std::uint64_t accountSoid{};
  116. std::uint64_t characterSoid{};
  117. std::uint64_t acquiredInstanceSoid{};
  118. /** True when the same revision also publishes the charged profile-material balances. */
  119. bool updatesAccount{};
  120. };
  121. /** Validated socket-action after-image for one item upsert and optional material balances. */
  122. struct SocketPlug {
  123. SessionState after{};
  124. std::uint32_t accountDefinitionId{};
  125. std::uint32_t itemInstanceDefinitionId{};
  126. std::uint64_t accountSoid{};
  127. std::uint64_t characterSoid{};
  128. std::uint64_t targetInstanceSoid{};
  129. bool updatesAccount{};
  130. };
  131. /** Validated subclass item-instance after-image for one ability socket-entry selection. */
  132. struct SubclassSelection {
  133. SessionState after{};
  134. std::uint32_t itemInstanceDefinitionId{};
  135. std::uint64_t accountSoid{};
  136. std::uint64_t characterSoid{};
  137. std::uint64_t subclassInstanceSoid{};
  138. };
  139. /** Validated profile-stack acquisition after-image for an account upsert and optional resident. */
  140. struct ProfileItemAcquisition {
  141. SessionState after{};
  142. std::uint32_t accountDefinitionId{};
  143. /** Family-4 slot-three schema used by a resident-backed shader or modification stack. */
  144. std::uint32_t itemInstanceDefinitionId{};
  145. std::uint64_t accountSoid{};
  146. /** Stable profile-row identity, or zero for a non-actionable currency/material stack. */
  147. std::uint64_t acquiredInstanceSoid{};
  148. /** Shared installed-build classifier copied from the prepared State mutation. */
  149. bool actionSource{};
  150. /** True only when this revision appends the resident at the prior manifest tail. */
  151. bool appendedResident{};
  152. };
  153. /** Validated item-dismantle after-image for one character upsert and one instance release. */
  154. struct ItemDismantle {
  155. SessionState after{};
  156. std::uint32_t accountDefinitionId{};
  157. std::uint32_t characterDefinitionId{};
  158. std::uint32_t itemInstanceDefinitionId{};
  159. std::uint64_t accountSoid{};
  160. std::uint64_t characterSoid{};
  161. std::uint64_t dismantledInstanceSoid{};
  162. /** True when the same revision also publishes credited profile materials. */
  163. bool updatesAccount{};
  164. };
  165. /** Queuez fields published after every staged frame is copied to caller output. */
  166. struct StagedPublication {
  167. SessionState after{};
  168. bool hasState{};
  169. /** The Family-4 companion went out and owes its delayed second copy. */
  170. bool armsFamily4Repush{};
  171. /** Root the companion used, kept because an unmapped snapshot records no residents. */
  172. std::uint64_t family4RepushRoot{};
  173. /**
  174. * A family-zero body went out and owes its delayed second copy.
  175. * An answer inside the same exchange reaches the record before it writes its new state, so it
  176. * is refused. The delayed copy is the one that lands.
  177. */
  178. bool armsBannerRepush{};
  179. /** Root that copy must use. */
  180. std::uint64_t bannerRepushRoot{};
  181. /**
  182. * Root a family-two subscribe was answered against, or zero when this frame answered none.
  183. *
  184. * A subscribe is the only moment a family-two root arrives. The connection keeps the last one
  185. * so a later re-push can reuse it rather than deriving a value the peer never named.
  186. */
  187. std::uint64_t socialRosterRepushRoot{};
  188. /**
  189. * An emblem equip left the published family-two object stale and it owes a fresh copy.
  190. *
  191. * The family-two snapshot is built when the peer subscribes, so the emblem it carries is only
  192. * correct as of that moment; the Client resolves that account-keyed object as *the* account
  193. * emblem, so a stale one pins the display for the rest of the session while the equip itself
  194. * keeps succeeding.
  195. *
  196. * Its own flag on its own signal. The banner arm is deliberately not reused: the consumer
  197. * records that arming a re-push from another family's signal took the connection down.
  198. */
  199. bool rearmsSocialRosterRepush{};
  200. /** A subclass selection just staged and owes a delayed ability-icon refresh. */
  201. bool armsAbilityRefresh{};
  202. };
  203. } // namespace sunrise::server::bap::encrypted::queuez