member_messages.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #pragma once
  2. #include <cstdint>
  3. #include "../../encoding/bit_reader.h"
  4. namespace sunrise::middleware::gameplay::group {
  5. /** Registry id a member uses to publish its own peer properties. */
  6. inline constexpr std::uint8_t kPeerPropertiesId = 31;
  7. /** Registry id a member uses to ask the host to add one player. */
  8. inline constexpr std::uint8_t kPlayerAddId = 34;
  9. /** Registry id a member uses to ask the host to remove its player. */
  10. inline constexpr std::uint8_t kPlayerRemoveId = 36;
  11. /** Registry id a member uses to publish a sparse change to its player record. */
  12. inline constexpr std::uint8_t kPlayerPropertiesId = 37;
  13. /** Declared decoded size of a peer-properties message. */
  14. inline constexpr std::uint32_t kPeerPropertiesSize = 408;
  15. /** Declared decoded size of a player-add message. */
  16. inline constexpr std::uint32_t kPlayerAddSize = 288;
  17. /** Declared decoded size of a player-remove message. */
  18. inline constexpr std::uint32_t kPlayerRemoveSize = 12;
  19. /** Declared decoded size of a player-properties message. */
  20. inline constexpr std::uint32_t kPlayerPropertiesSize = 288;
  21. /**
  22. * Leading fields of a peer-properties message.
  23. * The 304-byte property block after the address is not decoded.
  24. */
  25. struct PeerPropertiesHeader {
  26. std::uint64_t sessionId{};
  27. /** NetAddr method. 0 through 5 carry 41 address bytes; 6 and 7 carry 85. */
  28. std::uint8_t addressMethod{};
  29. };
  30. /**
  31. * Leading fields of a player-add message.
  32. * The 232-byte player block and its 20-byte tail after them are not decoded.
  33. */
  34. struct PlayerAddRequest {
  35. std::uint64_t sessionId{};
  36. std::uint64_t playerId{};
  37. std::uint32_t sequence{};
  38. /** Player kind, 0 through 3. */
  39. std::uint8_t kind{};
  40. };
  41. /**
  42. * Reads the session id and address method of a peer-properties message.
  43. * @param reader Reader positioned at the body.
  44. * @param output Receives the fields.
  45. * @return True when both were present.
  46. */
  47. [[nodiscard]] bool read_peer_properties_header(encoding::bits::Reader& reader,
  48. PeerPropertiesHeader& output) noexcept;
  49. /**
  50. * A player-remove message. It names no player: the identity comes from the bound peer state.
  51. */
  52. struct PlayerRemoveRequest {
  53. std::uint64_t sessionId{};
  54. };
  55. /**
  56. * Leading fields of a player-properties message.
  57. * The 232-byte sparse player record and its 20-byte tail after them are not decoded.
  58. */
  59. struct PlayerPropertiesRequest {
  60. std::uint64_t sessionId{};
  61. std::uint32_t sequence{};
  62. /** Player kind, 0 through 3. */
  63. std::uint8_t kind{};
  64. };
  65. /**
  66. * Reads the identity fields of a player-add message.
  67. * @param reader Reader positioned at the body.
  68. * @param output Receives the fields.
  69. * @return True when every field was present and the reserved bit read zero.
  70. */
  71. [[nodiscard]] bool read_player_add(encoding::bits::Reader& reader,
  72. PlayerAddRequest& output) noexcept;
  73. /**
  74. * Reads a whole player-remove message.
  75. * @param reader Reader positioned at the body.
  76. * @param output Receives the session id.
  77. * @return True when both fields were present and the reserved bit read zero.
  78. */
  79. [[nodiscard]] bool read_player_remove(encoding::bits::Reader& reader,
  80. PlayerRemoveRequest& output) noexcept;
  81. /**
  82. * Reads the leading fields of a player-properties message.
  83. * @param reader Reader positioned at the body.
  84. * @param output Receives the fields.
  85. * @return True when every field was present and the reserved bit read zero.
  86. */
  87. [[nodiscard]] bool read_player_properties_header(encoding::bits::Reader& reader,
  88. PlayerPropertiesRequest& output) noexcept;
  89. } // namespace sunrise::middleware::gameplay::group