Botcraft 1.21.5
Loading...
Searching...
No Matches
PacketFactory.cpp
Go to the documentation of this file.
5
6namespace ProtocolCraft
7{
8 namespace
9 {
10 template<typename TypesTuple>
11 std::shared_ptr<Packet> AutomaticPacketFactory(const int id)
12 {
13 std::shared_ptr<Packet> output = nullptr;
14
15 Internal::loop<std::tuple_size_v<TypesTuple>>([&](auto i) {
16 if (id == i)
17 {
18 output = std::make_shared<std::tuple_element_t<i, TypesTuple>>();
19 }
20 });
21
22 return output;
23 }
24 }
25
26 std::shared_ptr<Packet> CreateClientboundPacket(const ConnectionState state, const int id)
27 {
28 switch (state)
29 {
31 return AutomaticPacketFactory<AllClientboundLoginPackets>(id);
33 return AutomaticPacketFactory<AllClientboundStatusPackets>(id);
35 return AutomaticPacketFactory<AllClientboundPlayPackets>(id);
36#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
38 return AutomaticPacketFactory<AllClientboundConfigurationPackets>(id);
39#endif
40 default:
41 return nullptr;
42 }
43 }
44
45 std::shared_ptr<Packet> CreateServerboundPacket(const ConnectionState state, const int id)
46 {
47 switch (state)
48 {
50 return AutomaticPacketFactory<AllServerboundHandshakingPackets>(id);
52 return AutomaticPacketFactory<AllServerboundLoginPackets>(id);
54 return AutomaticPacketFactory<AllServerboundStatusPackets>(id);
56 return AutomaticPacketFactory<AllServerboundPlayPackets>(id);
57#if PROTOCOL_VERSION > 763 /* > 1.20.1 */
59 return AutomaticPacketFactory<AllServerboundConfigurationPackets>(id);
60#endif
61 default:
62 return nullptr;
63 }
64 }
65}
std::shared_ptr< Packet > CreateClientboundPacket(const ConnectionState state, const int id)
std::shared_ptr< Packet > CreateServerboundPacket(const ConnectionState state, const int id)