queuez_state_validation.h 11 KB

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