queuez_state_validation.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #pragma once
  2. #include <cstdint>
  3. #include <span>
  4. #include "../../../../middleware/queuez/queuez_update.h"
  5. #include "../../../../middleware/queuez/subscription.h"
  6. #include "definition.h"
  7. namespace sunrise::state {
  8. struct PendingRecordRewardGrant;
  9. }
  10. namespace sunrise::server::bap::encrypted::queuez {
  11. /** @return True when one peer queuez state is canonical for the implemented versions. */
  12. [[nodiscard]] bool valid(const SessionState& state) noexcept;
  13. /**
  14. * Stages publication of one whole Family-4 snapshot.
  15. * @param before Current queuez state owned by the peer.
  16. * @param family Prepared Family-4 snapshot whose object payloads stay borrowed.
  17. * @param after Gets the state published once the snapshot frame is copied.
  18. * @return True for a first snapshot or an identical version-zero replay.
  19. */
  20. [[nodiscard]] bool stage_family4_snapshot(const SessionState& before,
  21. const middleware::queuez::Family& family,
  22. SessionState& after) noexcept;
  23. /** Replaces an active peer's Family-4 manifest with a full next-version snapshot. */
  24. [[nodiscard]] bool stage_family4_refresh(const SessionState& before,
  25. const middleware::queuez::Family& family,
  26. SessionState& after) noexcept;
  27. /**
  28. * Decides whether one family-zero subscription publishes, and as which kind of frame.
  29. * A repeat naming the character the pair already holds reports no publish and no version bump.
  30. * Both callers send anyway, so the answer is which frame to build, not whether to answer.
  31. * @param before Current queuez state owned by the peer.
  32. * @param selectedCharacter Character the family-zero pair names now.
  33. * @param publish Gets whether a frame is needed.
  34. * @param incremental Gets whether that frame is an incremental, not a full snapshot.
  35. * @param after Gets the state published after the whole response transaction.
  36. * @return True when the request is canonical for the current state.
  37. */
  38. [[nodiscard]] bool stage_family0_subscription(const SessionState& before,
  39. std::uint64_t selectedCharacter,
  40. bool& publish,
  41. bool& incremental,
  42. SessionState& after) noexcept;
  43. /**
  44. * Decides whether one validated Family-3 subscription publishes a snapshot.
  45. * @param before Current queuez state owned by the peer.
  46. * @param subscription Family selector the Client asked for.
  47. * @param publish Gets whether a svc-123 frame is needed.
  48. * @param after Gets the state published after the whole response transaction.
  49. * @return True when the selector belongs to the active post-change root, where that is needed.
  50. */
  51. [[nodiscard]] bool stage_family3_subscription(const SessionState& before,
  52. const middleware::queuez::Subscription& subscription,
  53. bool& publish,
  54. SessionState& after) noexcept;
  55. /**
  56. * Stages the fixed first opcode-505 transition for one peer.
  57. * @param before Current queuez state owned by the peer.
  58. * @param change Gets the version-one after-image and the account definition.
  59. * @return True only when a version-zero Family-4 manifest is in place.
  60. */
  61. [[nodiscard]] bool stage_change_character(const SessionState& before,
  62. ChangeCharacter& change) noexcept;
  63. /**
  64. * Stages the Family-4 increment that moves the character object to the picked character.
  65. * @param before Current queuez state owned by the peer.
  66. * @param selectedCharacterSoid Character key the ws-504 request named.
  67. * @param select Gets the after-image, both object definitions and both character keys.
  68. * @return True only when an existing manifest names a different resident character.
  69. */
  70. [[nodiscard]] bool stage_select_character(const SessionState& before,
  71. std::uint64_t selectedCharacterSoid,
  72. SelectCharacter& select) noexcept;
  73. /**
  74. * Stages one Family-4 version increment without changing its resident manifest.
  75. * @param before Current queuez state owned by the peer.
  76. * @param characterSoid Selected character whose equipment changed.
  77. * @param swap Gets the checked version after-image and resident definition.
  78. * @return True only when the named character object is resident in active Family 4.
  79. */
  80. [[nodiscard]] bool stage_equipment_swap(const SessionState& before,
  81. std::uint64_t characterSoid,
  82. EquipmentSwap& swap) noexcept;
  83. /**
  84. * Stages one same-character Family-0 appearance-record increment after an equipment swap.
  85. * Family zero already owns the record, so the character key is preserved and only its version
  86. * ladder advances.
  87. *
  88. * @param before Peer state after the corresponding Family-4 character upsert.
  89. * @param characterSoid Selected character whose rendered equipment changed.
  90. * @param refresh Gets the exact combined Family-4/Family-0 after-image.
  91. * @return True only when active Family zero already names the same character.
  92. */
  93. [[nodiscard]] bool stage_character_appearance_refresh(const SessionState& before,
  94. std::uint64_t characterSoid,
  95. CharacterAppearanceRefresh& refresh) noexcept;
  96. /**
  97. * Advances the active Family-3 ladder for one appearance refresh.
  98. * @param before Peer state after any paired Family-4 and Family-0 frames.
  99. * @param characterSoid Character whose Family-3 record changes.
  100. * @param includeRoster Whether the account roster body changes in the same increment.
  101. * @param refresh Gets the exact +1 Family-3 after-image.
  102. * @return True only for an active roster store rooted with the peer's account family.
  103. */
  104. [[nodiscard]] bool stage_roster_appearance_refresh(const SessionState& before,
  105. std::uint64_t characterSoid,
  106. bool includeRoster,
  107. RosterAppearanceRefresh& refresh) noexcept;
  108. /**
  109. * Stages one Family-4 version increment without changing its resident manifest.
  110. * @param before Current active peer state.
  111. * @param accountSoid Account root the peer's family is rooted with.
  112. * @param characterSoid Selected resident character owning the changed item.
  113. * @param targetInstanceSoid Existing resident item-instance key to upsert.
  114. * @param updatesAccount True when the account object rides the same increment.
  115. * @param socketPlug Gets the exact +1 version and item-instance schema id.
  116. * @return True when both the selected character and target instance are resident exactly once.
  117. */
  118. [[nodiscard]] bool stage_socket_plug(const SessionState& before,
  119. std::uint64_t accountSoid,
  120. std::uint64_t characterSoid,
  121. std::uint64_t targetInstanceSoid,
  122. bool updatesAccount,
  123. SocketPlug& socketPlug) noexcept;
  124. /** Stages one resident subclass item-instance upsert without changing the Family-4 manifest. */
  125. [[nodiscard]] bool stage_subclass_selection(const SessionState& before,
  126. std::uint64_t accountSoid,
  127. std::uint64_t characterSoid,
  128. std::uint64_t subclassInstanceSoid,
  129. SubclassSelection& selection) noexcept;
  130. /**
  131. * Stages one Family-4 increment that adds a new resident item and updates its character.
  132. *
  133. * @param before Current active peer state.
  134. * @param accountSoid Account root the peer's family is rooted with.
  135. * @param characterSoid Selected resident character receiving the item.
  136. * @param acquiredInstanceSoid Fresh item-instance SOID absent from the resident manifest.
  137. * @param updatesAccount True when the account object rides the same increment.
  138. * @param acquisition Gets the exact +1 version and appended resident after-image.
  139. * @return True when both schemas resolve and the manifest has one free resident slot.
  140. */
  141. [[nodiscard]] bool stage_item_acquisition(const SessionState& before,
  142. std::uint64_t accountSoid,
  143. std::uint64_t characterSoid,
  144. std::uint64_t acquiredInstanceSoid,
  145. bool updatesAccount,
  146. ItemAcquisition& acquisition) noexcept;
  147. /**
  148. * Stages one Family-4 version increment for a full resident account-object upsert.
  149. * A profile row with a nonzero action-source SOID must already be resident when its stack grows,
  150. * or is appended once when Collections creates it. Currency rows keep a zero SOID.
  151. * @param before Current active peer state.
  152. * @param accountSoid Account root receiving the profile stack.
  153. * @param acquiredInstanceSoid Profile action-source key, or zero for a non-actionable stack.
  154. * @param actionSource Shared installed-build classification from the prepared State mutation.
  155. * @param appended True when the account mutation created a new profile row.
  156. * @param acquisition Gets the exact +1 version, definitions, and optional manifest append.
  157. * @return True when the account/root and optional profile resident transition are exact.
  158. */
  159. [[nodiscard]] bool stage_profile_item_acquisition(const SessionState& before,
  160. std::uint64_t accountSoid,
  161. std::uint64_t acquiredInstanceSoid,
  162. bool actionSource,
  163. bool appended,
  164. ProfileItemAcquisition& acquisition) noexcept;
  165. /** Stages one version containing a complete multi-row record reward and claim. */
  166. [[nodiscard]] bool stage_record_reward_grant(const SessionState& before,
  167. std::uint64_t accountSoid,
  168. std::uint64_t characterSoid,
  169. std::span<const std::uint64_t> appendedResidents,
  170. RecordRewardGrant& grant) noexcept;
  171. /** Stages a prepared record-reward grant, appending the residents its new instances need. */
  172. [[nodiscard]] bool stage_record_reward_grant(const SessionState& before,
  173. const state::PendingRecordRewardGrant& pending,
  174. RecordRewardGrant& grant) noexcept;
  175. /**
  176. * Stages one Family-4 increment that removes an item resident and updates its character.
  177. *
  178. * @param before Current active peer state.
  179. * @param accountSoid Account root the peer's family is rooted with.
  180. * @param characterSoid Selected resident character losing the item.
  181. * @param dismantledInstanceSoid Existing item-instance SOID to release.
  182. * @param updatesAccount True when the account object rides the same increment.
  183. * @param dismantle Gets the exact +1 version and compacted resident after-image.
  184. * @return True when both schemas and both named residents exist exactly once.
  185. */
  186. [[nodiscard]] bool stage_item_dismantle(const SessionState& before,
  187. std::uint64_t accountSoid,
  188. std::uint64_t characterSoid,
  189. std::uint64_t dismantledInstanceSoid,
  190. bool updatesAccount,
  191. ItemDismantle& dismantle) noexcept;
  192. /** Clears one named family. Another family, root or an inactive record changes nothing. */
  193. void stage_unsubscription(const SessionState& before,
  194. std::uint32_t familyType,
  195. std::uint64_t familyRootSoid,
  196. SessionState& after) noexcept;
  197. } // namespace sunrise::server::bap::encrypted::queuez