Botcraft 1.21.4
Loading...
Searching...
No Matches
ServerboundKeyPacket.hpp
Go to the documentation of this file.
1#pragma once
3
4#if PROTOCOL_VERSION > 758 /* > 1.18.2 */
6#endif
7
8namespace ProtocolCraft
9{
10 class ServerboundKeyPacket : public BaseMessage<ServerboundKeyPacket>
11 {
12 public:
13 static constexpr std::string_view packet_name = "Key";
14
15 SERIALIZED_FIELD(KeyBytes, std::vector<unsigned char>);
16#if PROTOCOL_VERSION < 759 /* < 1.19 */
17 SERIALIZED_FIELD(Nonce, std::vector<unsigned char>);
18#elif PROTOCOL_VERSION < 761 /* < 1.19.3 */
19 DEFINE_CONDITION(IsHasNonceOn, GetHasNonce());
20 DEFINE_CONDITION(HasSaltSignature, !GetHasNonce());
21
23 SERIALIZED_FIELD_WITHOUT_GETTER_SETTER(Nonce, Internal::Conditioned<std::vector<unsigned char>, &THIS::IsHasNonceOn>);
25#else
26 SERIALIZED_FIELD(EncryptedChallenge, std::vector<unsigned char>);
27#endif
28
30
31#if PROTOCOL_VERSION > 758 /* > 1.18.2 */ && PROTOCOL_VERSION < 761 /* < 1.19.3 */
32 protected:
33 bool GetHasNonce() const
34 {
35 return HasNonce;
36 }
37
38 GETTER(Nonce);
40 public:
41 auto& SetNonce(const std::optional<std::vector<unsigned char>>& Nonce_)
42 {
43 Nonce = Nonce_;
44 HasNonce = Nonce.has_value();
45 if (Nonce.has_value())
46 {
47 SaltSignature = std::nullopt;
48 }
49 return *this;
50 }
51
52 auto& SetSaltSignature(const std::optional<ProtocolCraft::SaltSignature>& SaltSignature_)
53 {
54 SaltSignature = SaltSignature_;
55 HasNonce = !SaltSignature.has_value();
56 if (SaltSignature.has_value())
57 {
58 Nonce = std::nullopt;
59 }
60 return *this;
61 }
62#endif
63 };
64} // ProtocolCraft
#define SERIALIZED_FIELD_WITHOUT_GETTER_SETTER(Name,...)
Define a field that will be automatically integrated in Read/Write and Json serialization We start by...
#define DEFINE_CONDITION(Name,...)
Define a condition that can be used later inside an Internal::Conditioned type.
#define SERIALIZED_FIELD(Name,...)
#define GETTER(Name)
static constexpr std::string_view packet_name
SERIALIZED_FIELD(KeyBytes, std::vector< unsigned char >)
SERIALIZED_FIELD(EncryptedChallenge, std::vector< unsigned char >)
A type wrapper to conditionally serialize a type.
Definition Templates.hpp:83