LeviLamina
Loading...
Searching...
No Matches
Packet.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/common/SubClientId.h"
7#include "mc/deps/raknet/PacketPriority.h"
8#include "mc/network/Compressibility.h"
9#include "mc/network/MinecraftPacketIds.h"
10#include "mc/network/NetworkPeer.h"
11#include "mc/network/packet/cerealize/core/SerializationMode.h"
12#include "mc/platform/Result.h"
13
14// auto generated forward declare list
15// clang-format off
16class BinaryStream;
19namespace cereal { struct ReflectionCtx; }
20// clang-format on
21
22class Player;
23class Actor;
24class BlockPos;
27
28class Packet {
29public:
30 [[nodiscard]] constexpr explicit Packet(
31 PacketPriority priority = PacketPriority::MediumPriority,
32 NetworkPeer::Reliability reliability = NetworkPeer::Reliability::ReliableOrdered,
33 SubClientId clientSubId = SubClientId::PrimaryClient,
34 bool compress = true
35 )
36 : mPriority(priority),
37 mReliability(reliability),
38 mSenderSubId(clientSubId),
39 mCompressible(compress ? Compressibility::Compressible : Compressibility::Incompressible) {}
40
46 LLAPI void sendTo(Player const& player) const;
47
54 LLAPI void sendTo(BlockPos const& pos, DimensionType dimId, optional_ref<Player const> except = std::nullopt) const;
55
62 LLAPI void sendTo(Actor const& actor, optional_ref<Player const> except = std::nullopt) const;
63
70 LLAPI void sendToClient(NetworkIdentifier const& identifier, ::SubClientId clientId) const;
71
72 LLAPI void sendToClient(NetworkIdentifierWithSubId const& identifierWithSubId) const;
73
77 LLAPI void sendToClients() const;
78
79 LLAPI void sendToClients(NetworkIdentifier const& exceptId, ::SubClientId exceptSubid) const;
80
81public:
82 // member variables
83 // NOLINTBEGIN
84 ::PacketPriority mPriority;
85 ::NetworkPeer::Reliability mReliability;
86 ::SubClientId mSenderSubId;
87 bool mIsHandled;
88 ::std::chrono::steady_clock::time_point mReceiveTimepoint;
89 ::IPacketHandlerDispatcher const* mHandler;
90 ::Compressibility mCompressible;
91 // NOLINTEND
92
93public:
94 // virtual functions
95 // NOLINTBEGIN
96 virtual ~Packet();
97
98 virtual ::MinecraftPacketIds getId() const = 0;
99
100 virtual ::std::string getName() const = 0;
101
102 virtual uint64 getMaxSize() const;
103
104 virtual ::Bedrock::Result<void> checkSize(uint64 packetSize, bool receiverIsServer) const;
105
106 virtual void writeWithSerializationMode(
107 ::BinaryStream& bitStream,
108 ::cereal::ReflectionCtx const& reflectionCtx,
109 ::std::optional<::SerializationMode>
110 ) const;
111
112 virtual void write(::BinaryStream& bitStream, ::cereal::ReflectionCtx const& reflectionCtx) const;
113
114 virtual void write(::BinaryStream&) const = 0;
115
116 virtual ::Bedrock::Result<void>
117 read(::ReadOnlyBinaryStream& bitStream, ::cereal::ReflectionCtx const& reflectionCtx);
118
119 virtual ::Bedrock::Result<void> read(::ReadOnlyBinaryStream& bitStream);
120
121 virtual bool disallowBatching() const;
122
123 virtual bool isValid() const;
124
125 virtual ::SerializationMode getSerializationMode() const;
126
127 virtual void setSerializationMode(::SerializationMode);
128
129 virtual ::std::string toString() const;
130
131 virtual ::Bedrock::Result<void>
132 _read(::ReadOnlyBinaryStream& bitStream, ::cereal::ReflectionCtx const& reflectionCtx);
133
134 virtual ::Bedrock::Result<void> _read(::ReadOnlyBinaryStream&) = 0;
135 // NOLINTEND
136
137public:
138 // member functions
139 // NOLINTBEGIN
140 MCAPI ::Bedrock::Result<void> readNoHeader(
141 ::ReadOnlyBinaryStream& bitstream,
142 ::cereal::ReflectionCtx const& reflectionCtx,
143 ::SubClientId const& subid
144 );
145 // NOLINTEND
146
147public:
148 // destructor thunk
149 // NOLINTBEGIN
150 MCFOLD void $dtor();
151 // NOLINTEND
152
153public:
154 // virtual function thunks
155 // NOLINTBEGIN
156 MCFOLD uint64 $getMaxSize() const;
157
158 MCAPI ::Bedrock::Result<void> $checkSize(uint64 packetSize, bool receiverIsServer) const;
159
160 MCAPI void $writeWithSerializationMode(
161 ::BinaryStream& bitStream,
162 ::cereal::ReflectionCtx const& reflectionCtx,
163 ::std::optional<::SerializationMode>
164 ) const;
165
166 MCAPI void $write(::BinaryStream& bitStream, ::cereal::ReflectionCtx const& reflectionCtx) const;
167
168 MCFOLD ::Bedrock::Result<void>
169 $read(::ReadOnlyBinaryStream& bitStream, ::cereal::ReflectionCtx const& reflectionCtx);
170
171 MCAPI ::Bedrock::Result<void> $read(::ReadOnlyBinaryStream& bitStream);
172
173 MCFOLD bool $disallowBatching() const;
174
175 MCFOLD bool $isValid() const;
176
177 MCFOLD ::SerializationMode $getSerializationMode() const;
178
179 MCFOLD void $setSerializationMode(::SerializationMode);
180
181 MCFOLD ::std::string $toString() const;
182
183 MCFOLD ::Bedrock::Result<void>
184 $_read(::ReadOnlyBinaryStream& bitStream, ::cereal::ReflectionCtx const& reflectionCtx);
185
186
187 // NOLINTEND
188
189public:
190 // vftables
191 // NOLINTBEGIN
192 MCNAPI static void** $vftable();
193 // NOLINTEND
194};
195
196namespace ll {
197template <class PacketPayloadT>
198class PayloadPacket : public ::Packet, public PacketPayloadT {
199public:
200 using PayloadType = PacketPayloadT;
201
202 template <typename... Args>
203 PayloadPacket(Args&&... args) : Packet(),
204 PacketPayloadT(std::forward<Args>(args)...) {}
205};
206} // namespace ll
Definition Actor.h:105
Definition BinaryStream.h:11
Definition BlockPos.h:19
Definition IPacketHandlerDispatcher.h:12
Definition NetworkIdentifier.h:10
LLAPI void sendTo(Player const &player) const
LLAPI void sendToClient(NetworkIdentifier const &identifier, ::SubClientId clientId) const
LLAPI void sendTo(BlockPos const &pos, DimensionType dimId, optional_ref< Player const > except=std::nullopt) const
LLAPI void sendToClients() const
static MCAPI void ** $vftable()
LLAPI void sendTo(Actor const &actor, optional_ref< Player const > except=std::nullopt) const
Definition Player.h:125
Definition ReadOnlyBinaryStream.h:8
Definition optional_ref.h:10
Definition NetworkIdentifierWithSubId.h:10
Definition ReflectionCtx.h:11