web_service_runtime.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include <cstddef>
  3. #include <cstdint>
  4. #include <span>
  5. #include <variant>
  6. #include "../../middleware/web_service/messages/opcode206.h"
  7. #include "../../state/runtime/runtime.h"
  8. namespace sunrise::server::web_service {
  9. /** Optional Server action produced while answering one Web Service request. */
  10. struct Outcome {
  11. bool hasSubscription{};
  12. middleware::queuez::Subscription subscription{};
  13. /** An opcode-504 pick moved the selection and its Family-4 object still has to follow. */
  14. bool hasSelectedCharacter{};
  15. std::uint64_t selectedCharacterSoid{};
  16. /** A request prepares at most one State mutation; the alternative owns only that payload. */
  17. using Mutation = std::variant<std::monostate,
  18. state::PendingEquipmentSwap,
  19. state::PendingSubclassSelection,
  20. state::PendingItemAcquisition,
  21. state::PendingProfileItemAcquisition,
  22. state::PendingItemDismantle,
  23. state::PendingSocketPlug,
  24. state::PendingItemState>;
  25. Mutation mutation{};
  26. };
  27. /** @return The prepared mutation of the requested type, or null when another route ran. */
  28. template <typename Mutation>
  29. [[nodiscard]] const Mutation* mutation_if(const Outcome& outcome) noexcept {
  30. return std::get_if<Mutation>(&outcome.mutation);
  31. }
  32. /** Records the final opcode-403/404 reply after its paired Family-4 version is known. */
  33. void report_equip_response(const middleware::web_service::Message& message,
  34. std::int32_t family4Version,
  35. std::span<const std::byte> response) noexcept;
  36. /** Records an item-creation reply after its exact Family-4 version and instance are known. */
  37. void report_item_acquisition_response(const middleware::web_service::Message& message,
  38. std::int32_t family4Version,
  39. std::uint64_t acquiredInstanceSoid,
  40. std::span<const std::byte> response) noexcept;
  41. /** Records the final profile-stack creation reply and exact Family-4 account revision. */
  42. void report_profile_item_acquisition_response(const middleware::web_service::Message& message,
  43. std::int32_t family4Version,
  44. std::uint32_t definitionHash,
  45. std::int32_t quantity,
  46. std::span<const std::byte> response) noexcept;
  47. /** Records a dismantle reply after its exact Family-4 version and removed instance are known. */
  48. void report_item_dismantle_response(const middleware::web_service::Message& message,
  49. std::int32_t family4Version,
  50. std::uint64_t dismantledInstanceSoid,
  51. std::span<const std::byte> response) noexcept;
  52. /** Records a socket-action reply after its exact item-instance Family-4 revision is known. */
  53. void report_socket_plug_response(const middleware::web_service::Message& message,
  54. std::int32_t family4Version,
  55. std::uint64_t targetInstanceSoid,
  56. std::uint8_t socketLane,
  57. std::uint16_t plugDefinitionIndex,
  58. std::span<const std::byte> response) noexcept;
  59. /** Records an opcode-801 reply after its exact subclass item-instance revision is known. */
  60. void report_subclass_selection_response(const middleware::web_service::Message& message,
  61. std::int32_t family4Version,
  62. const state::PendingSubclassSelection& mutation,
  63. std::span<const std::byte> response) noexcept;
  64. /**
  65. * Answers one whole supported Web Service request body.
  66. * @param request Whole decrypted svc-10 body.
  67. * @param response Svc-11 response-body storage owned by the caller.
  68. * @param written Gets the encoded response-body size, or zero when the header does not parse.
  69. * @return False only when the envelope header does not parse.
  70. */
  71. [[nodiscard]] bool consume(std::span<const std::byte> request,
  72. std::span<std::byte> response,
  73. std::size_t& written) noexcept;
  74. /**
  75. * Answers one request and reports any subscription side effect.
  76. * @param request Whole decrypted svc-10 body.
  77. * @param response Svc-11 response-body storage owned by the caller.
  78. * @param written Gets the encoded response-body size, or zero when the header does not parse.
  79. * @param outcome Gets the prepared action for the caller to publish, and is left empty when
  80. * the action was refused or the reply could not be encoded.
  81. * @return False only when the envelope header does not parse.
  82. */
  83. [[nodiscard]] bool consume(std::span<const std::byte> request,
  84. std::span<std::byte> response,
  85. std::size_t& written,
  86. Outcome& outcome) noexcept;
  87. } // namespace sunrise::server::web_service